Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Store string of fields names marked as yes into new field

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi experts,

I have a bunch of yes/no fields in the project record:

Screen-Shot-2018_2D00_04_2D00_02-at-12.37.38-PM.png

I also have a multi-select option set:

Screen-Shot-2018_2D00_04_2D00_02-at-12.37.57-PM.png

I need to collect all of the fields names marked as "yes" and store the string in a new field. I also need to collect all the values in the multi-select option set and build a text string and store in a new field (this is mainly because I cannot use multi-select option set in a workflow email).

How can I do the same? I'm sure there is no out of the box way to do this.

Thanks,

Jon

*This post is locked for comments

  • Verified answer
    gdas Profile Picture
    gdas 50,089 on at
    RE: Store string of fields names marked as yes into new field

    Hi Jon,

    Instead of Xrm.Page.getAttribute("new_sitewatchmodule").getName()  you just use hard coded value because you already know the field name .

    like below -

                if (Xrm.Page.getAttribute("new_sitewatchmodule").getValue() != null)
                    arr[i++] ="new_sitewatchmodule";
                if (Xrm.Page.getAttribute("new_pwbcmodule").getValue() != null)
                    arr[i++] ="new_pwbcmodule";
                if (Xrm.Page.getAttribute("new_xccmodule").getValue() != null)
                    arr[i++] ="new_xccmodule";
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Store string of fields names marked as yes into new field

    Hi Goutam,

    I used debugger then it started showing values. However, it is showing "Yes" text and not the names of the field marked as Yes. I need to display the field names.

    Screen-Shot-2018_2D00_04_2D00_03-at-12.43.10-PM.png

    function CreateString()
    {
        var arr= new Array(); //Array declaration 
        var i=0;
        var x="";  // initialize the variable
        if(Xrm.Page.getAttribute("new_sitewatchmodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_sitewatchmodule").getName();
        if(Xrm.Page.getAttribute("new_pwbcmodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_pwbcmodule").getName();
        if(Xrm.Page.getAttribute("new_xccmodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_xccmodule").getName();
        if(Xrm.Page.getAttribute("new_tunnelwatchmodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_tunnelwatchmodule").getName();
        if(Xrm.Page.getAttribute("new_vpdmodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_vpdmodule").getName();
        if(Xrm.Page.getAttribute("new_controllerinterfacemodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_controllerinterfacemodule").getName();
        if(Xrm.Page.getAttribute("new_xptmodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_xptmodule").getName();
        if(Xrm.Page.getAttribute("new_fastpassmodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_fastpassmodule").getName();
        if(Xrm.Page.getAttribute("new_armmodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_armmodule").getName();
        if(Xrm.Page.getAttribute("new_carpicsmodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_carpicsmodule").getName();
        if(Xrm.Page.getAttribute("new_salmodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_salmodule").getName();
        if(Xrm.Page.getAttribute("new_replicationmodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_replicationmodule").getName();
        if(Xrm.Page.getAttribute("new_quicklubepromodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_quicklubepromodule").getName();
        if(Xrm.Page.getAttribute("new_standalonequicklubemodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_standalonequicklubemodule").getName();
        if(Xrm.Page.getAttribute("new_washcapmodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_washcapmodule").getName();
        if(Xrm.Page.getAttribute("new_smartcodesmodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_smartcodesmodule").getName();
        if(Xrm.Page.getAttribute("new_dataimportmodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_dataimportmodule").getName();
        if(Xrm.Page.getAttribute("new_aimodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_aimodule").getName();
        if(Xrm.Page.getAttribute("new_odbcmodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_odbcmodule").getName();
        if(Xrm.Page.getAttribute("new_worldgiftmodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_worldgiftmodule").getName();
        if(Xrm.Page.getAttribute("new_washcardmodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_washcardmodule").getName();
        if(Xrm.Page.getAttribute("new_pindebitmodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_pindebitmodule").getName();
        if(Xrm.Page.getAttribute("new_websiteconnectmodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_websiteconnectmodule").getName();
        if(Xrm.Page.getAttribute("new_ibamodule").getValue()!=null)
            arr[i++]=Xrm.Page.getAttribute("new_ibamodule").getName();
    
        //copy paste for all yes/no fields 
        for(i=0;i<arr.length;i++)
        {
            if(arr[i]=="Yes")
                x+=arr[i]+",";
        }
        Xrm.Page.getAttribute("new_moduleslist").setValue(x);
    
    }


    Thanks,
    Jon

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 on at
    RE: Store string of fields names marked as yes into new field

    Hi Jon,

    Are you getting any error ?Try to add hard coded value at the time of declaration of variable x = "Yes," , seems there was null value assigned to variable x.

    Also you may debug the code. Just write debugger; in the beginning of the function and press F12 and trigger the function.

    Hope this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Store string of fields names marked as yes into new field

    The field that I'm setting the values into is new_moduleslist and its a simple text field.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Store string of fields names marked as yes into new field

    Hi Goutam,

    There is no script error now, but the the field is not setting the values.

    Thanks,

    Jon

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 on at
    RE: Store string of fields names marked as yes into new field

    Hi Jon ,

    Here is the modified code . Hope this will work.

     function CreateString()
            {
                var arr= new Array(); //Array declaration 
                var i=0;
                var x="";  // initialize the variable
                if(Xrm.Page.getAttribute("new_sitewatchmodule").getValue()!=null)
                    arr[i++]=Xrm.Page.getAttribute("new_sitewatchmodule").getValue();
                if(Xrm.Page.getAttribute("new_pwbcmodule").getValue()!=null)
                    arr[i++]=Xrm.Page.getAttribute("new_pwbcmodule").getValue();
                if(Xrm.Page.getAttribute("new_xccmodule").getValue()!=null)
                    arr[i++]=Xrm.Page.getAttribute("new_xccmodule").getValue();
                if(Xrm.Page.getAttribute("new_salmodule").getValue()!=null)
                    arr[i++]=Xrm.Page.getAttribute("new_salmodule").getValue();
                if(Xrm.Page.getAttribute("new_replicationmodule").getValue()!=null)
                    arr[i++]=Xrm.Page.getAttribute("new_replicationmodule").getValue();
                if(Xrm.Page.getAttribute("new_quicklubepromodule").getValue()!=null)
                    arr[i++]=Xrm.Page.getAttribute("new_quicklubepromodule").getValue();
                if(Xrm.Page.getAttribute("new_standalonequicklubemodule").getValue()!=null)
                    arr[i++]=Xrm.Page.getAttribute("new_standalonequicklubemodule").getValue();
                if(Xrm.Page.getAttribute("new_washcapmodule").getValue()!=null)
                    arr[i++]=Xrm.Page.getAttribute("new_washcapmodule").getValue();
                if(Xrm.Page.getAttribute("new_smartcodesmodule").getValue()!=null)
                    arr[i++]=Xrm.Page.getAttribute("new_smartcodesmodule").getValue();
                if(Xrm.Page.getAttribute("new_dataimportmodule").getValue()!=null)
                    arr[i++]=Xrm.Page.getAttribute("new_dataimportmodule").getValue();
                if(Xrm.Page.getAttribute("new_aimodule").getValue()!=null)
                    arr[i++]=Xrm.Page.getAttribute("new_aimodule").getValue();
                if(Xrm.Page.getAttribute("new_odbcmodule").getValue()!=null)
                    arr[i++]=Xrm.Page.getAttribute("new_odbcmodule").getValue();
    
                //copy paste for all yes/no fields 
                for(i=0;i<arr.length;i++)
                {
                    if(arr[i]=="Yes")
                        x+=arr[i]+",";
                }
                Xrm.Page.getAttribute("new_moduleslist").setValue(x);
    
            }


  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Store string of fields names marked as yes into new field

    Hi Goutam,

    I used the array approach in my code. I'm running the web resource onSave but its giving me script error: function not defined at eval.

    Please help me where I may be going wrong. Here's my code:

    function CreateString()
    {
    	var arr[]= new Array();
    	var i=0;
    	var x;
    	if(Xrm.Page.getAttribute("new_sitewatchmodule").getValue()!=null)
    		arr[i++]=Xrm.Page.getAttribute("new_sitewatchmodule").getValue();
    	if(Xrm.Page.getAttribute("new_pwbcmodule").getValue()!=null)
    		arr[i++]=Xrm.Page.getAttribute("new_pwbcmodule").getValue();
    	if(Xrm.Page.getAttribute("new_xccmodule").getValue()!=null)
    		arr[i++]=Xrm.Page.getAttribute("new_xccmodule").getValue();
    	if(Xrm.Page.getAttribute("new_salmodule").getValue()!=null)
    		arr[i++]=Xrm.Page.getAttribute("new_salmodule").getValue();
    	if(Xrm.Page.getAttribute("new_replicationmodule").getValue()!=null)
    		arr[i++]=Xrm.Page.getAttribute("new_replicationmodule").getValue();
    	if(Xrm.Page.getAttribute("new_quicklubepromodule").getValue()!=null)
    		arr[i++]=Xrm.Page.getAttribute("new_quicklubepromodule").getValue();
    	if(Xrm.Page.getAttribute("new_standalonequicklubemodule").getValue()!=null)
    	   arr[i++]=Xrm.Page.getAttribute("new_standalonequicklubemodule").getValue();
    	if(Xrm.Page.getAttribute("new_washcapmodule").getValue()!=null)
    		arr[i++]=Xrm.Page.getAttribute("new_washcapmodule").getValue();
    	if(Xrm.Page.getAttribute("new_smartcodesmodule").getValue()!=null)
    		arr[i++]=Xrm.Page.getAttribute("new_smartcodesmodule").getValue();
    	if(Xrm.Page.getAttribute("new_dataimportmodule").getValue()!=null)
    		arr[i++]=Xrm.Page.getAttribute("new_dataimportmodule").getValue();
    	if(Xrm.Page.getAttribute("new_aimodule").getValue()!=null)
    		arr[i++]=Xrm.Page.getAttribute("new_aimodule").getValue();
    	if(Xrm.Page.getAttribute("new_odbcmodule").getValue()!=null)
    		arr[i++]=Xrm.Page.getAttribute("new_odbcmodule").getValue();
    
    	//copy paste for all yes/no fields 
    	for(i=0;i<arr.length;i++)
    	{
    		if(arr[i]=="Yes")
    			x+=arr[i]+",";
    	}
    	Xrm.Page.getAttribute("new_moduleslist").setValue(x);
    
    }


    Thanks,

    Jon

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Store string of fields names marked as yes into new field

    Hi Goutam,

    Thanks a lot. That should work for my requirement.

    Thanks,

    Jon

  • Verified answer
    gdas Profile Picture
    gdas 50,089 on at
    RE: Store string of fields names marked as yes into new field

    Hi Jon ,

    In that case mentioned one by one those you in the  "if condition" so it will add only those which you have not mentioned in the "if condition "

    var AllAttributes = Xrm.Page.data.entity.attributes.get();
    var listofAttribute;
    var listOfValues;
    if (AllAttributes != null) {
        for (var i in AllAttributes) {
            var fieldName = AllAttributes[i].getName();
            if (fieldName != "MultiselectFieldName" && fieldName != "YesNoField1"  && fieldName != "YesNoField2") {  //Mentioned one by one those you dont need in the if condition so it will add only those which you have not menttioned 
    
                listOfValues += Xrm.Page.getAttribute(fieldName).getValue() + "\n" + ","; 
    
                listofAttribute += oppAttributes[i].getName() + "\n" + ",";
            }
    
        }
    }


  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Store string of fields names marked as yes into new field

    Hi Goutam,

    I meant that besides the yes/no fields in the screenshot above, there are more yes/no fields and I don't want to store their values in my string.

    Thanks,

    Jon

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans