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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Somebody can help me with this code? (Want verify boolean)

(0) ShareShare
ReportReport
Posted on by
Hello everybody!
I've a trouble with this script OnSaved, because I need that when "attributeValue" get values:
"null or false" it makes "moveToNext = false".
I've tried with if ((attributeValue == null) || (attributeValue == false)), but when
I'm in the process with this "changed" it don't work (don't move to the next stage with
any value [true or false]).

And when I let only if (attributeValue == null) , it work (move to the next stage), but
can move with any value [true or false], because they not are null.

For example:
Stage 1: Identify Client
var innitialcommunication {1: Si, 0: No} [two option by default]
var customerneed { text lines}

When innitialcommunication == si/true/1 and customerneed != null,
you'll move to Stage 2 when saved.
----------------------------------
function Move() { //debugger; //Control var (boolean) var moveToNext = true; //gets the stageObject var stageObj = Xrm.Page.data.process.getActiveStage(); // Returns a collection of steps in the stage. var stepsCollection = stageObj.getSteps(); //loop on the stepsColletion for (var i = 0; i < stepsCollection.getLength(); ++i) { // Returns the logical name of the attribute associated to the step. var stepAttributeName = stepsCollection.get(i).getAttribute(); // Retrieves the data value for an attribute. var attributeValue = Xrm.Page.getAttribute(stepAttributeName).getValue(); //if attribute is null set moveToNext to false if ((attributeValue == null)) { moveToNext = false; } } // If all attributes contain data if (moveToNext) { //Move to the next stage Xrm.Page.data.process.moveNext(); } }
----------------------------------------

PD: I'm not a master in JavaScript in CRM, I'm learning, but I've seen somes videos and
I don't get where is my mistake.
For your time Thanks You.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Somebody can help me with this code? (Want verify boolean)

    Thaks man, with this change out from loop it worked!!

    Another dude!, Do you know how use moveNext() to go to other Stage? For Example:

    Stage 1 : Identify - Stage 2: Development Solution - Stage 3: Negociation - Stage 4: Lost Opportunity ; I want apply a move from X Stage to Stage 4 if the client abandoned.

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Somebody can help me with this code? (Want verify boolean)

    Are you sure your logic is correct ?

    for (var i = 0; i < stepsCollection.getLength(); ++i) {
    	    // Returns the logical name of the attribute associated to the step.
    	    var stepAttributeName = stepsCollection.get(i).getAttribute();
    
    	    // Retrieves the data value for an attribute.
    	   	var attributeValue = Xrm.Page.getAttribute(stepAttributeName).getValue();
    
    	    //if attribute is null set moveToNext to false
    		 if ((attributeValue == null)) {
    	        moveToNext = false;	
    			}
    		
    	} 

    I think you have to check the Bold code above. When it inside loop, doesn't it only refers to the latest value ?

    For example:

    There are 5 loops.

    Loop 1 : stepAttributeName  = false;
    
    Loop 2 : stepAttributeName  = false;
    
    Loop 3 : stepAttributeName  = true;
    
    Loop 4 : stepAttributeName  = false;
    
    Loop 5 : stepAttributeName  = true;
    
    

    Though there are 3 false, your code will only refers to the loop number 5. 

    CMIIW

    All you need to do is jump out from the loop if there is a single attribute contains false. So you will have 

    moveToNext = False

    Or you can use LIST Variable to catch every value you get from the loop and check if there are false inside the LIST

  • Suggested answer
    JohnAnonymous Profile Picture
    5,241 on at
    RE: Somebody can help me with this code? (Want verify boolean)

    Have you tried putting a debugger statement in your code and inspecting the values?

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#3
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans