Policy Automation for B2C Service

Get Involved. Join the Conversation.

Topic

    Jayandan Rajaram
    Read or write attributes from OPA using JavaScript
    Topic posted February 13, 2018 by Jayandan RajaramRed Ribbon: 250+ Points 
    187 Views, 7 Comments
    Title:
    Read or write attributes from OPA using JavaScript
    Content:

    Is it possible to read or write attributes from OPA using JavaScript. Here the Scenario is we are having Entity holding more than one instance of an attribute where we need to retrieve all the data(all instances of that attribute) from OPA to JavaScript.PFA for the explanation of scenario where an attribute holding 3 instances,can we retrieve the data of all three instances from OPA to JavaScript??

    Image:

    Comment

     

    • Anuj Behl

      Hi,

      Yes, it is possible to get the value of OPA attributes using JavaScript. You can use jQuery selectors to get the attribute element node and then get the value of that field. This will only work when the attribute is placed on the interview screen in focus.

      -Anuj

    • Davin Fifield

      Direct use of jQuery to access or manipulate interview screens is definitely not recommended, since it is likely to change behavior between versions.

      A much better approach is to use interview extensions to work with interview controls that are on the screen.

      See also this thread for background.

      Davin.

       

       

    • Anuj Behl

      I completely agree with Davin, sorry I did not mention this in my original comment. This is more of a hack than a general solution.

      And thank you for mentioning interview extensions, I didn't know about these.

      -Anuj

    • Jayandan Rajaram

      Hi Davin/Anuj,

                            Here the Scenario is we have to retrieve 101,102,103(all instances of Exception attribute)to Java Script. PFA ,where we have written 3 rules for exception entity and we are unable to use entity class in javascript as we are retiving instances using relationship here. PFA  for more clarity on scenario.

      Please find sample code to retrieve only one instance to JS. Here "opmCtl14" is ID of one instance and i am not able to get alert(ex:101 data) in OPA interview screen after debug.

      OraclePolicyAutomation.AddExtension
      (
      {
      customEntityContainer: function(control,interview)
      {
      return
      {
       var x = document.getElementById("opmCtl14").value;
      alert(x);
      }
      alert('hi');
      }
      }
      );
    • Anuj Behl

      Hi Jayandan,

      We would need more details. Where did you write this JS code? Are you sure the execution is reaching this line of code?

      -Anuj

    • Jayandan Rajaram

      Hi Anuj,

                  We need some data(all instances of Exception attribute which is output of rule validation) to be sent to OSC Database from OPA as OPA is not having any Database.If we are able to retrieve this data to Java Script from OPA, then we can send this data from Java Script to OSC Data base through PHP.  

      The Code is sample POC code where i am trying to retrieve data of one instance i.e, var x = document.getElementById("opmCtl14").value; the output of that is 102, i am able to see in chrome console and i am not able to see in OPA Interview screen although we are alerting that variable.

    • Jayandan Rajaram

      Hi  guys,

                    Help on this implementation if you are aware on this scenario

      Is it possible to read or write attributes from OPA using API. Here the Scenario is we are having an Entity holding more than one instance of an attribute where we need to retrieve all the data(all instances of that attribute) from OPA using API .PFA for the explanation of scenario where an attribute holding 3 instances,can we retrieve the data of all three instances from OPA USING API??