Clarity Service Management

Expand all | Collapse all

Can we retrieve form field values from 2 different forms on the same Request, in 1 function before Request submission?

Jump to Best Answer
  • 1.  Can we retrieve form field values from 2 different forms on the same Request, in 1 function before Request submission?

    Posted 06-16-2016 03:57 AM

    Hi,

     

    We have a requirement in Service Catalog, where in we need to retrieve the values of 2 form fields from 2 different forms (or service options), compare their values and determine whether the user should be allowed to submit this request or not. This is required as both the options are different accesses a user would request for, and if the user does not select any of these 2 options he should not be allowed to submit the request. The problem is the service form also has a 3rd service option which triggers a another product webservice and is a mandate option in the Request, but does not hold any value without either of the other 2 options being selected.

     

    Can this be achieved in 12.8 or 14.1?

     

    Thanks,

    Paridhi



  • 2.  Re: Can we retrieve form field values from 2 different forms on the same Request, in 1 function before Request submission?

    Posted 07-08-2016 02:15 PM

    There are several ways to do this.  Here are just two methods:

     

    Example 1

    In Forms 1 and 2 you have values that you need in form 3.  When the fields change in forms 1 and 2 you create or update global/session variables.  Then you can access those variables from any other form.

     

    Example 2

    When form 3 needs to read a field from form 1 or 2 you can switch scope the source form, grab the data and store it in a variable, you then switch scope back to form 3 and use it as you need to.



  • 3.  Re: Can we retrieve form field values from 2 different forms on the same Request, in 1 function before Request submission?

    Posted 07-12-2016 02:34 AM

    Hi Derek,

     

    Could you please let us know a sample global session variable which can be used to store values in Catalog form?

    Also which Catalog JavaScript function would help us switch scope to the source form and retrieve value from it in the next form? Can this be achieved in 12.9 or only 14.1?

     

    Thanks,

    Paridhi



  • 4.  Re: Can we retrieve form field values from 2 different forms on the same Request, in 1 function before Request submission?

    Posted 07-12-2016 09:15 AM

    Paridhi,

     

    Could you please let us know a sample global session variable which can be used to store values in Catalog form?

     

    1.  Start off by declaring a global variable in the onload function of the source form.  The trick it to leave out the “var” keyword and the name must be unique to your browser session.  If you are not sure, then open your console browser to see if the name will cause a conflict (either because it is in use or too close to the name of an existing variable.)

     

    form_onLoad()

    {

                   // Initialize the global

                   myGlobal = somevalue;

    }

     

    2. Create an onChange or onBlur function for the field holding the value in the source form.  Read the value using the standard CA form functions and then update the global.

     

    field_onChange()

    {

                   // This function updates my global variable

    myGlobal = ca_fdGetTextFieldValue(ca_fd.formId, ‘myfieldname’);

    }

     

    3. Repeat steps 1-2 for each field you need to use elsewhere.

    4. Now you can use the new globals in your other code on the target form just like a local variable.

     

    Also which Catalog JavaScript function would help us switch scope to the source form and retrieve value from it in the next form? Can this be achieved in 12.9 or only 14.1?

     

    1. This method is more flexible but harder to use, as you need to know the scope and formId for each form you are working with.  Once you switch scope you can read an update the fields using the standard CA functions, just as if the code was part of the form you are switching to.  Remember you may need to switch back as well.  The function is available in both 12.9 and 14.1. I often combine with the first method (above) where I set up global variables to store the scope and formIds for the forms I care about.

     

    Syntax:  ca_fd.switchFdScope(scope, formId);

     

     

    Derek L. Cavour



  • 5.  Re: Can we retrieve form field values from 2 different forms on the same Request, in 1 function before Request submission?

    Posted 06-01-2018 04:56 PM

    Derek,

     

    Is there any example of the switchFdScope function working? I don't know where to find the "scope" value in a form.



  • 6.  Re: Can we retrieve form field values from 2 different forms on the same Request, in 1 function before Request submission?

    Posted 06-04-2018 09:50 AM

    (1) If you want to use the scope or form id within a form, you could define it like this:

     

    [Form 0 local variables defined in onload function]

    var scope = ca_fd.fdScope;

    var formId = ca_fd.formId;

     

    (2) If instead you want the variables to be globalc so you can switch between forms, you could do it like this:

     

    [Form 1 global variables defined in onload function]

    scopeForm1 = ca_fd.fdScope;

    formIdForm1 = ca_fd.formId;

     

    [Form 2 globalvariables defined in onload function]

    scopeForm2 = ca_fd.fdScope;

    formIdForm2 = ca_fd.formId;

     

    Note: The global variable names can be any non-reserved name you want and could also be stored in an object or array for indexing/iteration purposes.  (I create a data structure object called SOE that is accessible from every form. You can use the browser's console to view the variables.  If you are going to code with globals get used to using the console for debugging.)

     

    (3) Now that you have the global variables defined you can use the switch scope function.  Just substitute the global variables names for the arguments.

     

    syntax:

    ca_fd.switchFdScope(scope, formId);

     

    example:

    ca_fd.switchFdScope(scopeForm2, formIdForm2);

     

    Warning, you will need to use this function in many places to ensure output is going to the correct form or you are reading values from the correct form.  Also, you will need to switch scope in the body of a asynchronous function that is called.

     

      ca_reportQuery('getPolicyApprovers2', {'NAME':formId}, function updateFields(result)

      {

        if (result.length == 0) return;

        

        ca_fd.switchFdScope(scope,formId);

        approver_ids = result[0].approver_ids;

        ca_fdSetTextFieldValue(ca_fd.formId, 'policy_approver1', approver_ids);

        

      }, null);



  • 7.  Re: Can we retrieve form field values from 2 different forms on the same Request, in 1 function before Request submission?
    Best Answer

    Posted 07-11-2016 06:10 PM

    Hi Paridhi - Did derek.cavour's response help answer your question? If so please mark as Correct Answer. Thanks!