Dear Dynamics 365 community,
I am looking for a way to create a workflow to:
1. Convert options sets values (1,2,3,4 or 5) to numbers
2. Addition all the value from the option sets (there is 6 fields with all the same 1-5 option set)
With the final result, we want to have an indicator of the ''value'' for a prospect. Like if we set each 6 fields to 1, the value would be 6 wich is super low and we would not put efforts with this prospect.
I heard I would need to convert the data from the option sets fields to some dummy fields (hidden on the form) and then I would be able to addition these values. The problem is: I don't have any idea on how to do this and what would the workflow look like.
I'm turning to you guys to help me creating the workflow wich would convert the option sets to number and then addition all the dummy field to get the value of the prospects.
Hope you can help me with this,
Derek
*This post is locked for comments
Awesome, everything is now working exactly as expected.
Thanks a lot everyone for you time and effort in helping me solve this problem, that is really appreciated ! What an awesome community !
Have a nice day,
Derek
Just add
total = total - 500000000;
(after you have the sum)
The issue here is that when you created the options set values, you used the default numbering sequences from CRM.
For example: option 1 value is 100000001 instead of just 1.
If this environment is not in production yet, I would get back to my option sets and change the values of the items in the option sets from 100000001 to 1.
If that is not possible, add another piece of code in your total line:
var total = value1 + value2 +value3 + value4 + value5 - 500000000;
or if you used the getOptionSetValue line:
var total = getOptionSetValue("new_coteclient1") + getOptionSetValue("new_coteclient2") + getOptionSetValue("new_coteclient3")+ getOptionSetValue("new_coteclient4") + getOptionSetValue("new_coteclient5") - 500000000;
Hi Everyone, it is now working without the ''toString()'' with a wholer number field type, created new field to test it out.
But is there a way to substract a specific number? The value that shows is now the ''new_coteclientX'' sum + 500 000 000.
So let's say the sum would be 8, the total number shown is 500 000 008
Hi Derek,
You are saying that your new_total3 is a Single Line of text. You might need to do conversion from the results of your sum to the string field.
In the line where you are putting the result back in the field:
Xrm.Page.getAttribute("new_total3").setValue(total);
change the setValue parameter to a string value:
Xrm.Page.getAttribute("new_total3").setValue(total.toString());
If that does not work, put a couple of alerts in your code.
Maybe before the above line, do alert(total) to see if you get the result.
Simply change this
Xrm.Page.getAttribute("new_total3").setValue(total);
to this
Xrm.Page.getAttribute("new_total3").setValue(total.toString());
Or change the field type to Whole Number
Hi Derek,
give this a try - notice toString call there:
function TotalCoteClient()
{
var value1 = Xrm.Page.getAttribute("new_coteclient1").getValue();
var value2 = Xrm.Page.getAttribute("new_coteclient2").getValue();
var value3 = Xrm.Page.getAttribute("new_coteclient3").getValue();
var value4 = Xrm.Page.getAttribute("new_coteclient4").getValue();
var value5 = Xrm.Page.getAttribute("new_coteclient5").getValue();
var total = getOptionSetValue("new_coteclient1") + getOptionSetValue("new_coteclient2") + getOptionSetValue("new_coteclient3")+ getOptionSetValue("new_coteclient4") + getOptionSetValue("new_coteclient5");
Xrm.Page.getAttribute("new_total3").setValue(total.toString());
}
function getOptionSetValue(fieldName) {
var field = Xrm.Page.getAttribute(fieldName);
if (field != null) {
var fieldOption = field.getValue();
if (fieldOption != null)
return fieldOption;
else
return 0;
}
else return 0;
}
Hi Pawel,
Unfortunately, your code doesn't work either as it gives me the ''InvalidType'' error.
Hi Derek,
In order to get things sorted out, in your TotalCoteClient function, the first five lines are not being used at all. Let me explain:
You are calculating your total in the following line:
var total = getOptionSetValue("new_coteclient1") + getOptionSetValue("new_coteclient2") +
getOptionSetValue("new_coteclient3")+ getOptionSetValue("new_coteclient4") + getOptionSetValue("new_coteclient5");
That particular line does not reference any of the values that your retrieved from your fields above. It is basically the same as if I did:
var value1 = getOptionSetValue("new_coteclient1");
var value2 = getOptionSetValue("new_coteclient2");
var value3 = getOptionSetValue("new_coteclient3");
var value4 = getOptionSetValue("new_coteclient4");
var value5 = getOptionSetValue("new_coteclient5");
var total = value1 + value2 +value3 + value4 + value5;
It is not necessary to have them both.
You can modify the getOptionsSetValue with the changes that Alex made.
The final version can look like that, to simplify the understanding of the code:
function TotalCoteClient()
{
// get values from the 5 Options Sets
var value1 = getOptionSetValue("new_coteclient1");
var value2 = getOptionSetValue("new_coteclient2");
var value3 = getOptionSetValue("new_coteclient3");
var value4 = getOptionSetValue("new_coteclient4");
var value5 = getOptionSetValue("new_coteclient5");
// calculate the total of the options sets
var total = value1 + value2 +value3 + value4 + value5;
// insert values into option sets
Xrm.Page.getAttribute("new_total3").setValue(total);
}
function getOptionSetValue(fieldName) {
var field = Xrm.Page.getAttribute(fieldName);
if (field != null) {
var fieldOption = field.getValue();
if (fieldOption != null)
return fieldOption;
else
return 0;
}
return 0;
}
Good luck
Guys really, you can post formatted code on this forum, your posts are really hard to read... @Derek.paquet - please read my post with the code, it's quite different from yours and without the error that Alex mentioned...
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,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156