AnsweredAssumed Answered

Sorting ValueMap by specific parameter

Question asked by phinchey on Jun 6, 2017
Latest reply on Jun 15, 2017 by pier-olivier.tremblay

I have a Valuemap I have defined with 4 properties, which is then populated in PAM after parsing some data from Service Catalog.  For what I need to do with the data in the VM, I need to sort it by one parameter which has a date string in it, in the format of: "6/6/2017 16:30:47"

 

Now in the SC form, where we do something similar with the data in the original table format, the following works fine as a .sort function:

 

function(a, b){ a = new Date(a.dtpubcom); b = new Date(b.dtpubcom); return a>b ? 1 : a<b ? -1 : 0; }

 

but the same function in PAM returns an error with reason:

-- TypeError: org.mozilla.javascript.NativeDate@52bb5e0e is not a function, it is java.lang.String. (#62)

 

If I use:

 

(function(a, b){ a = parseDate(a.dtpubcom, 'MM/dd/yyyy HH:mm:ss'); b=parseDate(b.dtpubcom, 'MM/dd/yyyy HH:mm:ss'); return a>b ? 1 : a<b ? -1 : 0; })

 

as the sort function, no error, but the valuemap ends up all  messed up. Entries are repeated and others dropped, can show below where I used the convertValueToXml() function before and after sorting (and redacted user names) has the same number of entries but certain entries from before sorting are gone.  If someone has a bright idea to actually get this VM sorted correctly it would be great

 

<Presort>
<undefined>
<dtpubcom>6/6/2017 16:32:16</dtpubcom>
<pubcomuser>Last2, First2</pubcomuser>
<pubcom>cost review private</pubcom>
<priv>1</priv>
</undefined>
<undefined>
<dtpubcom>6/6/2017 16:33:28</dtpubcom>
<pubcomuser>Last2, First2</pubcomuser>
<pubcom>cost approval public</pubcom>
<priv>0</priv>
</undefined>
<undefined>
<dtpubcom>6/6/2017 16:32:23</dtpubcom>
<pubcomuser>Last2, First2</pubcomuser>
<pubcom>cost review public</pubcom>
<priv>0</priv>
</undefined>
<undefined>
<dtpubcom>6/6/2017 16:33:41</dtpubcom>
<pubcomuser>Last2, First2</pubcomuser>
<pubcom>cost approval private</pubcom>
<priv>1</priv>
</undefined>
<undefined>
<dtpubcom>6/6/2017 16:30:47</dtpubcom>
<pubcomuser>Last3, First3</pubcomuser>
<pubcom>mkt analysis private</pubcom>
<priv>1</priv>
</undefined>
<undefined>
<dtpubcom>6/6/2017 16:26:54</dtpubcom>
<pubcomuser>Last1, First1</pubcomuser>
<pubcom>initial public note</pubcom>
<priv>0</priv>
</undefined>
<undefined>
<dtpubcom>6/6/2017 16:27:56</dtpubcom>
<pubcomuser>Last1, First1</pubcomuser>
<pubcom>submit public</pubcom>
<priv>0</priv>
</undefined>
<undefined>
<dtpubcom>6/6/2017 16:30:35</dtpubcom>
<pubcomuser>Last3, First3</pubcomuser>
<pubcom>mkt analysis public</pubcom>
<priv>0</priv>
</undefined>
</Presort>
-----------------------------
<Postsort>
<undefined>
<dtpubcom>6/6/2017 16:26:54</dtpubcom>
<pubcomuser>Last1, First1</pubcomuser>
<pubcom>initial public note</pubcom>
<priv>0</priv>
</undefined>
<undefined>
<dtpubcom>6/6/2017 16:27:56</dtpubcom>
<pubcomuser>Last1, First1</pubcomuser>
<pubcom>submit public</pubcom>
<priv>0</priv>
</undefined>
<undefined>
<dtpubcom>6/6/2017 16:30:35</dtpubcom>
<pubcomuser>Last3, First3</pubcomuser>
<pubcom>mkt analysis public</pubcom>
<priv>0</priv>
</undefined>
<undefined>
<dtpubcom>6/6/2017 16:30:47</dtpubcom>
<pubcomuser>Last3, First3</pubcomuser>
<pubcom>mkt analysis private</pubcom>
<priv>1</priv>
</undefined>
<undefined>
<dtpubcom>6/6/2017 16:26:54</dtpubcom>
<pubcomuser>Last1, First1</pubcomuser>
<pubcom>initial public note</pubcom>
<priv>0</priv>
</undefined>
<undefined>
<dtpubcom>6/6/2017 16:30:35</dtpubcom>
<pubcomuser>Last3, First3</pubcomuser>
<pubcom>mkt analysis public</pubcom>
<priv>0</priv>
</undefined>
<undefined>
<dtpubcom>6/6/2017 16:27:56</dtpubcom>
<pubcomuser>Last1, First1</pubcomuser>
<pubcom>submit public</pubcom>
<priv>0</priv>
</undefined>
<undefined>
<dtpubcom>6/6/2017 16:30:47</dtpubcom>
<pubcomuser>Last3, First3</pubcomuser>
<pubcom>mkt analysis private</pubcom>
<priv>1</priv>
</undefined>
</Postsort>

Outcomes