IT Process Automation

Expand all | Collapse all

How to assign values to valuemap

Jump to Best Answer
  • 1.  How to assign values to valuemap

    Posted 07-04-2016 11:11 AM

    Hi ,

     

    I need to assign values in to a valuemap.

    I am trying to assign the values in a loop ,but i get the following error.


    -- msg.valuemap.invalid.fieldname

     

    [code]

    var valuemapDates= newValueMap();

    For (i=0;i<arr.length;i++){

        Process.finaldate=Process.dateArr[2]+"/"+Process.dateArr[1]+"/"+Process.dateArr[3];

        valuemapDates[Process.finaldate]=Process.finaldate;

    }

    [/code]



  • 2.  Re: How to assign values to valuemap
    Best Answer

     
    Posted 07-04-2016 12:52 PM

    I havent found it in the documentation, but in my experience, the parameter name for a ValueMap (the value between square brackets)  has to be a valid JavaScript variable name, so no slashes are allowed. Also, it can't start with a number.



  • 3.  Re: How to assign values to valuemap

    Posted 07-05-2016 08:37 AM

    Hi Chandar,

     

    You don't really explain what you are trying to achieve here, and you don't show what your data set looks like, so it is hard to give a concise solution.

     

    For the purposes of this comment, I will be assuming your original data is a multidimensional array (since you are trying to loop through it), and that it looks something like this:

     

    In this case, the following code would convert that multidimensional array into a ValueMap.  However, as Bill meswi01 mentioned, a ValueMap field name must be a valid JavaScript variable name, so you can't use /, -, or start it with a number.

     

    In my example, I am prepending the start of the variable name with date_ and replacing your / with an _ (as you can use underscores).

     

    [code]

    var valuemapDates= newValueMap();

    for (var i=0; i < Process.dateArr.length; i++) {

      var tmp_finaldate = Process.dateArr[i][1] + "/" + Process.dateArr[i][0] + "/" + Process.dateArr[i][2];

      var TmpVM_Name = "date_" + Process.dateArr[i][1]+"_"+Process.dateArr[i][0]+"_"+Process.dateArr[i][2];

      valuemapDates[TmpVM_Name] = tmp_finaldate;

    }

    Process.valuemapDates = valuemapDates;

    Process.ValueMapNames = getValueMapFields(Process.valuemapDates);

    Process.ValueMapDates = valuemapDates;

    [/code]

     

    The resulting ValueMap would look something like this:

     

    However, since ValueMaps are not indexed, you won't be able to access the list of ValueMap names directly, you will have to use getValueMapFields to put the field names into an indexed array, and use those names to access the ValueMap.

     

     

    So depending on what you plan on doing with the data, it might just be easier to store the values in a normal array which would look like this:

    [code]

    var normalarray = [];

    for (var i=0; i < arr.length; i++) {

      normalarray.push(Process.dateArr[i][1] + "/" + Process.dateArr[i][0] + "/" + Process.dateArr[i][2]);

    }

    Process.arrayDates = normalarray;

    [/code]

     

    I hope this helps you on your way.

     

    Ian



  • 4.  Re: How to assign values to valuemap

    Posted 07-14-2016 09:06 AM

    I've run into this exact same error as well and found that there was some weirdness with handling dynamically created value map arrays. I needed to help the array out by initializing it with a blank ValueMap. I was then able to add new value maps into it and manipulate them however I wanted on the fly. When you're finished with your work pop the empty out.

     

    Like so:

    var vm = newValueMap();

    var MyValueMapArr = [vm];

     

    Hope this helps!