CA Service Management

 View Only
  • 1.  CA Service Catalog: JavaScript - Call a JS function inForm A from Form B

    Posted 12 days ago

    Hello: Is there a way to share functions between forms?  For example, in a service offering option, I have two forms: frmSDM_Fields and frmCustomerInfo.  Let's say that in frmSDM_Fields that I want to call/utilize a function called testMe contained in frmCustomerInfo.  is there a way to do that?  I tried using the JavaScript export method and the JS editor on the form would not allow that.  I also tried ca_fd.js.frmCustomerInfo.testMe(); from the JavaScript contained in frmSDM_Fields.  That results in an object not defined error.

    Can anyone think of a way to make this work?  Thank you.  Scott



  • 2.  RE: CA Service Catalog: JavaScript - Call a JS function inForm A from Form B

    Broadcom Employee
    Posted 11 days ago

    Hi Scott,

    Is the requirement to update fields in second form from the first form script? function logic reuse (like include/import into another form) is not possible, but execution of function in second form script from first form script is possible.

    Regards,

    Satya Kiran




  • 3.  RE: CA Service Catalog: JavaScript - Call a JS function inForm A from Form B

    Posted 11 days ago

    Satya: Yes, regarding the requirement.  The ideal situation is to have a hidden form that has all my common functions on it.  Let's say I had a function that takes a string and makes the first letter upper-case and all remaining characters lowercase.  Rather than adding that function to every form, I would like to be able to funnel the input to a single function located within a form that I would include in all of my offerings.

    What is the context for calling a JavaScript function located within another form that is included with the offering option?  When calling a function within the same form, it is ca_fd.js.functionName().  That syntax probably would not work if Form A has the function and I am trying to call it from Form B.

    Thank you.  Scott




  • 4.  RE: CA Service Catalog: JavaScript - Call a JS function inForm A from Form B
    Best Answer

    Broadcom Employee
    Posted 11 days ago

    Hi Scott,

    I would suggest looking into custom_form_lib.js which is specifically in place to have common / utility functions which can be used in the form scripts.

    We can add a function in the custom_form_lib.js, for example as below.

    function example_func(val){
        return val.substring(0,5);
    }

    and access the function in form script as "example_func('some string value'):"

    Ref: Use JavaScript Functions in Fields (broadcom.com)

    For calling functions in another form, we can follow below process.

    Can we retrieve form field values from 2 different forms on the same Request, in 1 function before Request submission? | CA Service Management (broadcom.com)

    Please refer 6th response in above post, which would give the detailed steps.

    On a high level:

        We have to store the form scope and form id in global variables in onload function of the second form.

        We also have to store the current formscope and formid in local variables.

        We have to switch form scope before calling script function in second form, ca_fd.switchFdScope(scope, formId)

        After above switch scope, we can call the functions just like local functions in the current script as ca_fd.js.function_in_other_form();

        We have to switch back to current form scope.

    Regards,

    Satya Kiran




  • 5.  RE: CA Service Catalog: JavaScript - Call a JS function inForm A from Form B

    Posted 10 days ago

    Satya Kiran: The first solution worked.  I did not know that there was a custom JavaScript file.  I can move all my global functions and variables into that file and then call from any form, which is exactly what I wanted.  Thank You.