Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Create workflow to convert Option Sets data to number

Posted on by Microsoft Employee

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create workflow to convert Option Sets data to number

    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

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: Create workflow to convert Option Sets data to number

    Just add

    total = total - 500000000;

    (after you have the sum)

  • Verified answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Create workflow to convert Option Sets data to number

    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;

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create workflow to convert Option Sets data to number

    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

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Create workflow to convert Option Sets data to number

    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.

  • Verified answer
    tw0sh3ds Profile Picture
    tw0sh3ds 5,600 on at
    RE: Create workflow to convert Option Sets data to number

    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

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: Create workflow to convert Option Sets data to 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;

    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create workflow to convert Option Sets data to number

    Hi Pawel,

    Unfortunately, your code doesn't work either as it gives me the ''InvalidType'' error.

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Create workflow to convert Option Sets data to number

    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

  • Suggested answer
    tw0sh3ds Profile Picture
    tw0sh3ds 5,600 on at
    RE: Create workflow to convert Option Sets data to number

    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...

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,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans