How do I copy all the variables from a requested item to a change request's description?

HugoFirst
Kilo Sage

Context: In a catalog task, I have a UI action to create a change request.   When creating the change request, I need to copy the variables and values from the variables attached to the task's parental requested item.

 

While I know how to copy any specific variable from the task's parent to the change request's description field, I need a general method to copy whatever variables are present in the task's parental requested item to the change request's description field.   I suspect that it will involve enumerating over the current.parent.variables item, but for the life of me, I haven't even got to first base yet!

1 ACCEPTED SOLUTION

HugoFirst
Kilo Sage

Thank you everyone for the ideas.     They were insightfull and they helped guide me to the solution that I'm using.



To reiterate the context:   I have a UI Action " Create Change" in the catalog task record so that people can open a change record from a request.   The request often comes with catalog variables and I need to copy them to the change request's description. Here's a snippet of code that works:   The part that is missing is the instantiation of the change object with Glide Record to create the new change request, and the insertion afterward.



var lov = "\nList of Variables from Requested Item";   // lov = list of variables


for (var prop in current.parent.variables )


{


  lov = lov + "\n" + prop + " = " + current.parent.variables[prop].getDisplayValue();


}


change.description = change.description + lov;



--------------- new edits below this line ------------------------------------


The solution above copies the variables in a somewhat random way.   I decided to list them in a sorted order.


That way, with "intelligent variable names", like items could be sorted together.


The following code will copy the variables to the change.description field as the above examble:


I'm embarrassed to say how long it took me to figure this out and I invite you to show me an easier way to do this.


Again, this is missing is the instantiation of the change object with Glide Record to create the new change request, and the insertion afterward.



The code:



var lov     = "\n\n===== List of Variables from Requested Item (" + current.parent.number + ") =====";


var index = 0;


var array = [];


for (var prop in current.parent.variables )


{


      array[index] = prop;


      index++;


}


var sorted = array.sort();



for ( x = 0; x<sorted.length; x++)


{


      var key = sorted[x];


      var value = current.parent.variables[key].getDisplayValue();


      var line = "\n-> variable " + key + " = " + value;


      if ( /\n/m.test(value) )


      {


              line = "\n-> variable " + key + " (multi-line) follows: --\n" + value + "\n<--- end of multi line variable " + key + " ---";


      }


      lov = lov + line;


}


change.description = "From " + current.parent.number + " -> " + current.number + ": " + current.short_description + "\n" + current.description + lov;


View solution in original post

13 REPLIES 13

Aaron40
Kilo Guru

Steve,



Are your variables coming back in the order they were placed on the original record?


They come out in a "random" order. By random I mean that the order is not alphabetic, but the order is consistent.


I'm working on sorting the list now. I may also see if I can add in the label. But this will probably require an exchange with the database.


Inactive_Use603
Kilo Expert

this solution will help you with any type of variable


Variables Values to Description - Oslova Networks


Wow!   This looks like a full featured solution.   I can't wait to give it a shot.


Thank you Oscar!


Your solution really looks nice. But I fail to implement it.


  • I added it as a Script Include
  • In Record Producer, I added it to the 'What will it contain' script.

But the variables do not show up in the description. Am I doing something wrong?


I succeeded at implementing your solution, but it failed to execute due to some errors.


Apparently, 'question' is undefined.


After editing out the lines:


  • var choices = question.getChoiceList();
  • v = choices.getLabelOf(v);
  • var question = go.getQuestion();

it did work without a glitch!



So: excellent functionality, but need some bug fixing.