Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

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

Posted on by Microsoft Employee
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

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee 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
    Community Member Microsoft Employee 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
    M.T. Eikelenboom Profile Picture
    M.T. Eikelenboom 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans