Tips for setting an option set field to read-only upon saving in MS Dynamics CRM 2011, ensuring it remains read-only for subsequent use

I have implemented the following script to set my field as read-only on a CRM form upon saving it. My requirement is that the field should be editable for the user the first time, and once they select a value and save the form, it should become read-only for subsequent times. However, with the current script, refreshing the form makes the field editable again.

function Test() { 
debugger; 
Xrm.Page.ui.controls.get("new_test").setDisabled(true); 
Xrm.Page.data.entity.attributes.get("new_test").setSubmitMode("always"); 
//Xrm.Page.getAttribute("new_test").setSubmitMode("always"); 
Xrm.Page.data.entity.save(); 
}

Answer №1

Ensure that you implement the action within the onLoad function rather than onSave. If the picklist already has a selected value, make sure to disable it.

Invoke the formOnLoad() method during the form's onLoad event.

function formOnLoad() { 
    debugger; 
    if(Xrm.Page.getAttribute("new_test").getValue() != null){
        Xrm.Page.ui.controls.get("new_test").setDisabled(true); 
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide on how to enable the first dropdown menu item upon clicking in Bootstrap 5

I am using Bootstrap 5 dropdowns and have defined them as follows: <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4a2825253e393e382b3a0a7f647b">[email protected]</a>/ ...

Isolate the CSS formatting from the template within an AngularJS directive

Here is an angular directive I created for a template. I wanted to keep the css styling separate from the template so that when I use the custom tag in my html file like <my-box></my-box> or <my-box></my-box>, I can configure the cs ...

Conceal social media icons when hovering over specific images similar to the feature on the website medium

I am facing an issue with fading out social links that appear over medium and large images on a webpage. I want the social links to fade out when they are over the images and fade back in once they move off the images. The number of medium and large images ...

Extracting and passing a JSON object to a Spring controller

I have a file upload feature on my jsp page that specifically accepts json format files. I want to retrieve the uploaded json file and pass it to a Spring controller for further processing. This is how my javascript code appears: var file = this.files[0] ...

Placing an image overlay on a YouTube video does not have clickable functionality on devices such as iPods/iPhones

We have been experimenting with the YouTube iframe APIs, specifically incorporating an overlay image on top of a video. The idea is that by clicking on this image, users can skip ahead in the video. However, we've encountered an issue where the image ...

The v-html command displays unprocessed HTML code on the webpage

This is a visual representation of my component: <template> <div v-html="someHtml"></div> </template> <script> export default { name: "test", props: { someHtml: String, }, } </script&g ...

In the code, an expression react was encountered when an assignment or function call was expected

Can someone help me with this error I'm getting on lines 127, 130, and 138? I'm not sure what's wrong with the code, but I believe it might be a syntax error or something similar. Any assistance would be greatly appreciated. It's worth ...

The react boolean attribute is malfunctioning and the video is not playing automatically

I have a React component with a <video> element that includes the autoplay attribute. <video autoplay muted src="/vids/vid.mp4"> However, it does not work as expected. Interestingly, when I set autoplay="true", it starts wo ...

To enable the radio button upon clicking the list item in JavaScript, simply check the radio button

I am working with radio buttons Here is the HTML code: <input type="radio" class="first" name="bright" checked> <input type="radio" class="second" name="bright" > <input type=" ...

Issue with Slick Grid not updating after Ajax request

I need to update the data on a slick grid when a checkbox is clicked, using an ajax call to retrieve new data. However, I am facing issues where the slick grid does not refresh and the checkbox loses its state upon page load. Jsp: <c:if test="${info ...

What is preventing me from parsing JSON in JavaScript?

This JSON data consists of a single object: results[0] = { 'MAX(id)': 1 } The following code snippet is not functioning as intended: var text = results[0]; var obj = JSON.parse(text); console.log(obj.MAX(id)); ...

Steps for Setting the Value of a Dropdown Option Based on its Unique Identifier

<select id=workTypeSelection> <option id="-1">-Select a Work Type-</option> <option id="1">Common</option> <option id="3">Computer Maintenance</option> <option id="5">Facility Maintenance</ ...

Display elements exclusively when the class XY is in an active state using JavaScript

Hello everyone, I'm new to this platform and excited to share my first post. Currently, I find myself facing a major challenge as I navigate through a bootcamp program. I have been working on a website with different sections that require specific fu ...

Issue with setting headers in Express.js when using an exported function

Exploring testing methods with Express using Mocha, Chai, Chai-HTTP plugin, and MongoDB with Mongoose. One particular test is designed to check if MongoDB correctly handles errors when attempting to retrieve a document with a faulty _id value (too short). ...

I am attempting to link a child object literal with a parent object literal

In a practical sense, I believe I can provide a clearer description of the problem I am encountering. What I am trying to achieve is linking a child entity to its parent. In my current scenario, I have two models: owner and property. An owner can have mult ...

AngularJS enables seamless two-way data binding with DropDownList in the Model-View-Controller (M

As a beginner in AngularJS, I am currently experimenting with implementing 2-way data binding for the Gender Dropdown menu similar to what I have done with textboxes. Below is a snippet of code for the dropdown control: <div class="form-group"> ...

Display an HTML tag with JavaScript

My code is in both HTML and TS files. The content stored in the Description variable looks like this: <div>aaaa</div><div>bbbb</div><div>cccc</div> Currently, the output displays as follows: aaaabbbbcccc I want to modi ...

Is Polymer more of a comprehensive framework compared to just a library? What is the best way to implement web components in a modular fashion

Web components aim to modularize the web, independent of any specific framework being used. The Polymer project offers the ability to create web components without being tied to a particular framework, meaning they should be compatible with any framework. ...

Default outlined style set for all v-text-fields in Vuetify

Is there an easy method to modify the default value of the "outlined" props for all instances of "v-text-field" within a given project? Find more information here https://i.sstatic.net/ZAJWS.png ...

The process of accessing files from the filesystem using AngularJS

I have a JSON file that I want to use in my Angular application. I came across a discussion here suggesting the use of $http.get to load JSON from the filesystem. However, I am encountering an issue where I keep getting a "http://localhost:9000/jsonFile.js ...