Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Retaining selected options on html web resource

Posted on by Microsoft Employee

Hi experts,

I have created the following HTML web resource:

Screen-Shot-2018_2D00_02_2D00_09-at-3.49.37-PM.png

I have created this to substitute for multi select option set as the requirement is to view all values without having to click on the field and populating. 

I have applied this code to save the selected values:

function setListOnSave()
{
	
		//remove all SC Option set values
		Xrm.Page.getControl("new_os1").clearOptions();
		
		//Get all values of First div (Software Configuration) all check box value using class name SC
		var SC = Xrm.Page.getControl("WebResource_MultipleSelect").getObject().contentWindow.document.getElementsByClassName("SC");
		var tmp=null;
		for(var i=0;i<SC.length;i++)
		{
			if(SC[i].checked)
			{
					//getting label of checked check box
					tmp+="-"+SC[i].value;
					
					//setting checked check box value into option set
					var opt1 = new Option();
					opt1.text = SC[i].value;
					opt1.value = 100000000+i;
					Xrm.Page.getControl('new_os1').addOption(opt1);
						
			}
		}
		
		
		
		
}


Now, when I return to some record, it doesn't show the values that I had selected previously and again displays the checkboxes as empty. 

Am I going wrong somewhere? Do I have to make an addition to my code? 

Thanks!

Jon

*This post is locked for comments

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: Retaining selected options on html web resource

    Hi,

      try doing this on click of a button and see if that works (add a button to the web resource, hit it, see if your multiselect has been updated.. then hit save in CRM)

      I suspect onSave might be a bit tricky place for this kind of updates (CRM may actually be saving everything before your changes have been applied to the "attribute")

      If it works with the button, you might try doing it like this:

    - In the onsave, do what you are doing, then cancel onsave AND start a 500ms timer (setTimeout)

      Here is an example of preventDefault: https://neilparkhurst.com/2015/11/11/javascript-prevent-save/

    - In the timeout function, call save programmatically, but have a global var so in your on save handler you can bypass the step above

      Here is how you can use save:

      https://msdn.microsoft.com/en-us/library/gg334720.aspx#BKMK_save

      

  • Verified answer
    Darshik Profile Picture
    Darshik 295 on at
    RE: Retaining selected options on html web resource

    Hi ,

    Create one button on the HTML form, while click on the button check the value from the check box and stamped it into the mscrm text box in comma separated.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans