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
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.
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
Have you tried putting a debugger statement in your code and inspecting the values?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156