web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer Service forum

Javascript modification

(0) ShareShare
ReportReport
Posted on by 1,942

Hi all,

I want to get the boolean data type fields where value = yes, and instead of writing them to console i want to store in an array and set the value to a field. Can anyone help to update the below code to my requirement.

FYI- My CRM is online >9.0

function writebooleanfieldlables(){
var booleanfieldnames= [];
Xrm.Page.data.entity.attributes.forEach(
function (attribute, index){
if(attribute.getAttributeType() == "boolean")
{ booleanfieldnames.push(attribute.getName());}
});
if (booleanfieldnames.length > 0){
if(typeof console != "undefined"){
console.log(booleanfieldnames.join());
}
}
else {
if(typeof console != "undefined"){
console.log("No boolean field are detected");
}
}
}

Categories:
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Try to use following code:

    function writebooleanfieldlables(){
    	var booleanfieldnames= [];
    	Xrm.Page.data.entity.attributes.forEach(function (attribute, index){
    		if(attribute.getAttributeType() == "boolean" && attribute.getValue())
    		{ booleanfieldnames.push(attribute.getName());}
    	});
    
    	if (booleanfieldnames.length > 0){
    		if (Xrm.Page.getAttribute("fieldnamehere")){
    			Xrm.Page.getAttribute("fieldnamehere").setValue(booleanfieldnames.join());
    		}
    	} else {
    		if (Xrm.Page.getAttribute("fieldnamehere")){
    			Xrm.Page.getAttribute("fieldnamehere").setValue("No boolean field are detected");
    		}
    	}
    }


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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Customer Service

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans