IT Process Automation

Expand all | Collapse all

Dynamically generate 'Process.' variables

Jump to Best Answer
  • 1.  Dynamically generate 'Process.' variables

    Posted 04-22-2015 11:03 AM

    I'm trying to dynamically create 'Process.' variables based on a list of fields passed into PAM from Service Catalog. I would like to be able to create process variables with the same names as the fields passed in the SC forms. Say for example a userID is being passed in from catalog, I would like to be able to use a loop to iterate over an array of field names and dynamically generate a variable with the name of Process.userID. Currently we statically code every variable name(in multiple places) to create a process variable for it, a method that becomes error prone and time consuming as the number grows. 


    Any ideas would be appreciated



  • 2.  Re: Dynamically generate 'Process.' variables
    Best Answer

     
    Posted 04-23-2015 05:17 PM

    This is easily done.  Keep in mind that a variable, let's say 'Process.SerialNumber' can also be referred to as 'Process["SerialNumber"]'.  So you can so something like this:

     

    var formFields = ['field1', 'field2','field3'];

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

      Process[formFields[i]] = value[i];

    }

     

    This would create process variables Process.field1, Process.field2, Process.field3.



  • 3.  Re: Dynamically generate 'Process.' variables

    Posted 04-24-2015 07:56 AM

    Thank you Bill!

    This is fantastic, I've already got proof of concept code working



  • 4.  Re: Dynamically generate 'Process.' variables

    Posted 05-29-2015 11:14 AM

    Hello Bill, Good Afternoon!

     

    Imagina the next scenario:

     

    On Service Catalog Form, lets imagine a "new contact" form.

    That form can allow to input until 10 contacts in just one submission.

     

    Imagine that you only insert data for 3 contacts (each "Contact" have 5 text fields) ... how will you dinnamically create variables on pam?

     

    Greetings.

    Ivo



  • 5.  Re: Dynamically generate 'Process.' variables

    Posted 04-24-2015 09:24 AM

    Bill,

     

    Can you enlighten me on the how and why this solution works, or point me to some technical articles?

     

    Is 'Process' a custom String java class that is defined as part PAM?

     

    Elwynn



  • 6.  Re: Dynamically generate 'Process.' variables

     
    Posted 04-24-2015 10:17 AM

    I should start by saying I have no special insight into PAM internals; I'm just a content developer.

     

    From what I can see, 'Process' is a generic Javascript object (typeof(Process) : "object");  All JavaScript objects are also associative arrays, so that fact that

    'Process.field1'  is the same as 'Process[field1]' is built into JavaScript, not just PAM.  There is some discussion of this at this link:

     

    http://www.quirksmode.org/js/associative.html

     

    Bill



  • 7.  Re: Dynamically generate 'Process.' variables

    Posted 04-30-2015 01:56 PM

    Bill,

     

    Thanks for the explanation and the link!

    Your solution saved me well over 100 lines of hard coded assignments in at least 2 separate places.

     

    Elwynn.



  • 8.  Re: Dynamically generate 'Process.' variables

    Posted 05-02-2015 08:37 AM

    Hi Bill -

     

    I'm also JAD (just a developer).    I believe the Process object is actually an instance of a ValueMap, which is a bespoke data type - basically an associative array with pages so that it's prettier when you view it in PAM's dataset editor.  (CA folks, please correct me if I'm wrong about this!)

     

    Something useful you can do in unit testing is to write out the whole process dataset to the automation library like this:

     

    Datasets['myTestDataset'] = Process

     

    Then if you want to drive a test process later, you just need to import what you want from the test dataset.  (Note that there are a bunch of system variables in there, so just reversing the statement to Process = Datasets['myTestDataset'] won't work so well.)

     

    Hope this helps,

    Sam