web
You’re offline. This is a read only version of the page.
close
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

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

I have the same question (0)
  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Jon,
    Yes you are right OOB way you cant do it ,  you need write JS customization.

    Here is I am giving simple code reference to get all attributes names and value, hope you can get idea from below code.

    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") {
                if (Xrm.Page.getAttribute().getValue()) { // For Yes Value
                    listOfValues += Xrm.Page.getAttribute(fieldName).getValue() + "\n" + ",";// For Yes Value  ,I have used comma and  break you can add as per your requirement for seperator
                }
                else { 
                    listOfValues += Xrm.Page.getAttribute(fieldName).getValue() + "\n" + ","; //For No Value  ,I have used comma and  break you can add as per your requirement for seperator
                }
            }
            else
            {
                listOfValues += Xrm.Page.getAttribute(fieldName).getValue() + "\n" + ","; //For Multiselect Value  ,I have used comma and  break you can add as per your requirement for seperator
            }
    
            listofAttribute += oppAttributes[i].getName() + "\n" + ","; //All Field Name ,I have used comma and  break you can add as per your requirement for seperator
    
        }
    }
  • Community Member Profile Picture
    on at

    Hi Goutam,

    Thanks for the code sample,

    I'll try to play with this and get back to you if I have any queries.

    Thank!

    Jon

  • Community Member Profile Picture
    on at

    Hi Goutam,

    How would I add multiple fields in the if condition?

    Would I repeat this line after the comma? (Xrm.Page.getAttribute().getValue())

    Thanks,

    Jon

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Jon ,

    As you can see I have used for loop , you dont need to add another statement . Its <  listofAttribute += oppAttributes[i].getName() + "\n" + ",";> inside loop  <  for (var i in AllAttributes) { }  > , so you will get the expected output like below -

    FieldName1,

    FieldName,

    -----

    -----

  • Community Member Profile Picture
    on at

    Hi Goutam,

    Ok, I understand now. The only issue is that I have other Yes/No fields in the record also that I would not like to include.

    Thanks,

    Jon

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Jon ,

    For that also I have mentioned , you can see I have used an if  Condition where you just need to mentioned your multiselect field Name

      if (fieldName != "MultiselectFieldName") {

    So you need to remove else part of that if statement  so that it will consider only YES/No value.

    Hope this helps.

  • Community Member Profile Picture
    on at

    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

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    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
    on at

    Hi Goutam,

    Thanks a lot. That should work for my requirement.

    Thanks,

    Jon

  • Community Member Profile Picture
    on at

    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans