IT Process Automation

  • 1.  JavaScript in IRF

    Posted Apr 01, 2015 12:08 AM

    Hi,

    I'm using JavaScript to run SQL query to get values to dropdown in IRF form. I need to write login and password directly to JavaScript code. Is it possible to call such information from PAM configuration or global DataSet?

    Regards,

    Milan



  • 2.  Re: JavaScript in IRF

    Posted Apr 08, 2015 04:34 PM

    Hi,

    I've found some information about it in discussions on this forum and documentation that pointed me to function ca_pam_getDatasetData(dataSetExpression,callBack).

    I'm using in our IRF the dynamic dropdown that pulls data from SQL database. To query database we use function ca_pam_getSQLData(driverName,connectionURL,userName,password,query,callBack). We keep the information about sql login and password in JavaScript code. The function ca_pam_getDatasetData should help me to move these sensitive information to Dataset. Now I'm able to read requested information from dataset and display them using JavaScript alert or write down them to some text field in our IRF but for some reason I'm not able to pass them to ca_pam_getSQLData correctlly.

    On page 323 of Content Designer Guide I’ve found example 2 that tells that dataset expressions can be used:

    ca_pam_getSQLData('Datasets["/Forms/SQLDataset"].driverName','Datasets["/Forms/SQLDataset"].connectionURL','Datasets["/Forms/SQLDataset"].userName','Datasets["/Forms/SQLDataset"].password','Datasets["/Forms/SQLDataset"].query',callBack);

     

    I created the dataset with the exactly same path, names of variables and dataset name but it seems that dataset expressions are not recognized it returns errors. For example: com.ca.pam.client.util.OasisException: Login failed for user 'Datasets["/Forms/SQLDataset"].userName'.

    I tried to convert values:

    ca_pam_getSQLData(ca_pam_convertToJavaScriptObject('Datasets["/Forms/SQLDataset"].driverName'),ca_pam_convertToJavaScriptObject('Datasets["/Forms/SQLDataset"].connectionURL'),ca_pam_convertToJavaScriptObject('Datasets["/Forms/SQLDataset"].userName'),ca_pam_convertToJavaScriptObject('Datasets["/Forms/SQLDataset"].password'),ca_pam_convertToJavaScriptObject('Datasets["/Forms/SQLDataset"].query'),callBack);

    but it returned the error Unidentified Exception.

    Please can anyone send me working example?

    Thank you,

    Milan



  • 3.  Re: JavaScript in IRF

    Broadcom Employee
    Posted Apr 08, 2015 05:44 PM

    Hello Milan,

     

    I can't find this example on page 323 (or anywhere) in the 4.2 Content Designer Guide.  What version are you using?

     

    I have not done this for a SQL query, but I did work out an example for SOAP.  I don't think your example 2 from the guide is correct.  You will have to do multiple calls to ca_pam_getDatasetData to retrieve each of the dataset values and store each one in a JavaScript variable.  You would then use those JavaScript variables in the ca_pam_getSQLData call.

     

    Regards,

    Bill



  • 4.  Re: JavaScript in IRF

    Posted Apr 08, 2015 08:42 PM

    Hello Bill,

    the mentioned example 2 is in Content Designer Guide 4.2.0.2 but it seems that my PAM installation is Build: 4.2.0 only. Probably dataset expressions are not supported on my PAM version.

    I already tried the way you mentioned and I was able to get the requested values and display them via JavaScript alert or write them down to text field using ca_pam_setTextFieldValue function.  When I tried to pass the gathered value to ca_pam_getSQLData function it seems to be empty value because it displays following error:

    com.ca.pam.client.util.OasisException: Login failed for user ''.

    I tried to use ca_pam_getSQLData and also ca_pam_getDataUsingSQLQuery function but without success.

    I attached JavaScript code from my IRF.

     

    Thank you,

    Milan

    Attachment(s)

    zip
    script.txt.zip   853 B 1 version


  • 5.  Re: JavaScript in IRF

    Broadcom Employee
    Posted Apr 09, 2015 05:07 PM

    Milan,

    I wasn't aware of that new feature in 4.2.0.2.  That would make this a lot simpler!

     

    Your problem is that the functions userName() and password() don't return  a value.  You can see this if you add the line "alert(ca_fd.js.userName())" to function x.  The callBack.onSuccess functions do return a value, but those return values are ignored.  The call to ca_pam_getSQLData might complete before the callback functions are even called.  Functions like ca_pam_getDatasetData() that use callbacks are often awkward to work with.

     

    I wrote some code that will handle this, but it's complicated and kind of rough.  I will post it when I get it cleaned up,

     

    Bill



  • 6.  Re: JavaScript in IRF

    Posted Apr 10, 2015 07:20 AM

    Hello Bill,

    thank you for your help. I'll wait for your workaround.

    Regards,

    Milan



  • 7.  Re: JavaScript in IRF

    Posted Jun 08, 2015 05:09 PM

    I've installed and tested PAM 4.2 SP02. I was finally able to move connection and logon information from script to dataset.

     

    ca_pam_getDataUsingSQLQuery('Datasets["/myFolder/myDataset"].driverName','Datasets["/myFolder/myDataset"].connectionURL','Datasets["/myFolder/myDataset"].userName','Datasets["/myFolder/myDataset"].password',ca_fd.js.querySAS(),callBack);

    Milan



  • 8.  Re: JavaScript in IRF
    Best Answer

    Posted Sep 08, 2015 08:37 PM

    Hiya,

     

    I know this is a bit old, so, sorry for the necro, but this is an area that really plagued me for an extremely long time when working with call-backs inside SRF JS.

     

    Here is a method that I've found that works quite well:

     

    If you need to make multiple calls from different sources, or if you find yourself using callback functions a lot inside of PAM, a 'wrapper' function is a good way to keep your code a little more readable.

     

    What you do is basically this:

     

     

    {

    dataSetWrapper : function(path,handler){

      /*

      utility function - passes a Datasetpath to a 'handler' function to allow treating data in

      a dataset as if it were just a local JSON object.

    */

      var callBack = new Object();

     

      callBack.onSuccess = function(result)

      {

       var dataValue = ca_pam_convertToJavaScriptObject(result);

       handler(dataValue)

       }

      

      }

      callBack.onFailure = function (caught){

       alert("Data Not Found For:\n"+path)

       console.log(path)

       console.log(handler)

      }

     

      ca_pam_getDatasetData(path, callBack);

      }

    }

     

     

    This lets you build a generic function to just interact with whatever data you want. No you just call ca_fd.js.dataSetWrapper and then pass whatever function you want to execute on the dataset contents as an argument -

     

    If you want to nest multiple callback operations, just call the wrapper again from inside your handler function, and pass it the next handler function in your chain.

     

    I even went so far as to extend this function to take an optional third argument for scenarios in which I wanted to pass additional information to my handler.

     

    Some JS wizards out there might be better at dealing with callbacks then I am, and have other input to give here, but I found this method to suit my needs pretty well, so I thought I'd share it in case anyone else was struggling.