Forum Stats

  • 3,780,804 Users
  • 2,254,440 Discussions
  • 7,879,465 Comments

Discussions

Setting values using Rules is not working on customInputs

Hi,

I am using a number attribute for displaying cost. Using Rules, I was setting calculated values to this number attribute. Now I have applied customInput extension on this attribute and I dont see calculated values in this attribute.

Is there a way where I can set these calculated values to customInputs using Rules? Please advise

Tagged:

Best Answer

Answers

  • Richard Napier
    Richard Napier Member Posts: 328 Bronze Trophy

    Hello

    perhaps you could share some details of your project and the extension?

    is the attribute you are trying to access visible on the screen, or have you added it to the OPM data extension file and loaded it ( see the documentation https://documentation.custhelp.com/euf/assets/devdocs/unversioned/IntelligentAdvisor/en/Content/Guides/Developer_Guide/Web_Interviews/Styles_and_scripts/Allow_interview_extensions_access_data.htm?Highlight=Data%20on%20screen)

    if not, please let us have some more information and some snippets of code / screen shots to look at to help you

  • HarshadaK
    HarshadaK Member Posts: 12 Green Ribbon

    Hi Richard,

    The attribute is visible on Screen and I have also added it to the OPM data extension file. Still its not working.

  • Richard Napier
    Richard Napier Member Posts: 328 Bronze Trophy

    Hi HarshadaK

    Could you please share the custom Extension here, or at least

    1) The part of the code where you load the extension data

    2) The part where you try and access the attribute

    3) Any relevant object keys like validate and update

    Also, it would be useful to know the data model.

    Thanks!

  • Richard Napier
    Richard Napier Member Posts: 328 Bronze Trophy

    Hi

    Just one last comment. In your original question you said:

    "I am using a number attribute for displaying cost. Using Rules, I was setting calculated values to this number attribute. Now I have applied customInput extension on this attribute and I dont see calculated values in this attribute.

    Is there a way where I can set these calculated values to customInputs using Rules? Please advise"

    I assumed that the last line :

    Is there a way where I can set these calculated values to customInputs using Rules? Please advise

    was a spelling mistake. If you have rules that assign a value to the attribute, then I don't understand the objective of setting the value (since it is defined in a rule outcome). I thought you meant see these calculated values.

    If you are looking to set the value of an attribute then I assume that there are no longer rules to assign a value.

    It would be easier if you could share more information so we can judge better what the desired outcome and current situation is.

    Thanks

  • HarshadaK
    HarshadaK Member Posts: 12 Green Ribbon

    Hi Richard,

    Issue here is, before using customInput script, rule table was working completely fine. After applying customInput extension on Total cost attribute, I dont see the values returned by rule table on UI.

    Below is the rule table used to set attribute Total cost

    And below is the attribute setup on screen


    Below is the script for customInput on Total Cost attribute.

    OraclePolicyAutomation.AddExtension({

       customInput: function (control, interview) {

       if (control.getProperty("cost") == "true") {

          interview.getExtensionData();

          var noPermits = interview.getValue("NoOfPermits");

          console.log("noPermits ",noPermits);

       return {

                mount: function(el) {

                   divLabel = document.createElement("div");

                   divLabel.className = "govuk-input__wrapper";

                   el.appendChild(divLabel);

                   divLabelText = document.createElement("div");

                       divLabelText.className = "govuk-input__prefix";

                   divLabelText.innerHTML = "£";

                   divLabel.appendChild(divLabelText);

                   divLabelInput = document.createElement("input");

                       divLabelInput.className = "govuk-input govuk-input--width-5";

                   divLabelInput.id = "cost";

                   divLabelInput.name = "cost";

                   divLabelInput.type = "text";

                   divLabelInput.readOnly = true;

                   divLabel.appendChild(divLabelInput);

                   console.log("Value ",control.getValue());

                },

                update: function(el) {

             }

             }

             }

             }

             })

  • Richard Napier
    Richard Napier Member Posts: 328 Bronze Trophy
    edited Nov 30, 2021 8:55AM

    Hi

    I think you are mistyping the console.log method so you are not seeing the values. In the code below I've edited that and also placed the value in the textbox so you can see it:

    OraclePolicyAutomation.AddExtension({
    
    	customInput: function (control, interview) {
    
    		if (control.getProperty("test") == "test") {
    
    			return {
    
    				mount: function (el) {
    					interview.getExtensionData();
    
    					var noPermits = interview.getValue("NoOfPermits");
    
    					console.log("noPermits =" + noPermits);
    
    					divLabel = document.createElement("div");
    
    					divLabel.className = "govuk-input__wrapper";
    
    					el.appendChild(divLabel);
    
    					divLabelText = document.createElement("div");
    
    					divLabelText.className = "govuk-input__prefix";
    
    					divLabelText.innerHTML = "£";
    
    					divLabel.appendChild(divLabelText);
    
    					divLabelInput = document.createElement("input");
    
    					divLabelInput.className = "govuk-input govuk-input--width-5";
    
    					divLabelInput.id = "cost";
    
    					divLabelInput.name = "cost";
    
    					divLabelInput.type = "text";
    
    					divLabelInput.readOnly = true;
    					
    					divLabel.appendChild(divLabelInput);
    					
    					document.getElementById("cost").value = control.getValue()
    
    						console.log("Value = " + control.getValue());
    
    				},
    
    				update: function (el) {}
    
    			}
    
    		}
    
    	}
    
    })
    

    Which gives

    Regards

  • HarshadaK
    HarshadaK Member Posts: 12 Green Ribbon

    Hi Richard,

    I did necessary changes to script still Value is coming as null

    OraclePolicyAutomation.AddExtension({

       customInput: function (control, interview) {

       if (control.getProperty("cost") == "true") {      

       return {

                mount: function(el) {

                   interview.getExtensionData();

                   var noPermits = interview.getValue("NoOfPermits");

                      console.log("noPermits ",noPermits);

                   divLabel = document.createElement("div");

                   divLabel.className = "govuk-input__wrapper";

                   el.appendChild(divLabel);

                   divLabelText = document.createElement("div");

                       divLabelText.className = "govuk-input__prefix";

                   divLabelText.innerHTML = "£";

                   divLabel.appendChild(divLabelText);

                   divLabelInput = document.createElement("input");

                       divLabelInput.className = "govuk-input govuk-input--width-5";

                   divLabelInput.id = "cost";

                   divLabelInput.name = "cost";

                   divLabelInput.type = "text";

                   divLabelInput.readOnly = true;

                   divLabel.appendChild(divLabelInput);

                   document.getElementById("cost").value = control.getValue()

                   console.log("Value = " + control.getValue());

                },

                update: function(el) {

             }

             }

             }

             }

             })



  • Richard Napier
    Richard Napier Member Posts: 328 Bronze Trophy
    edited Nov 30, 2021 10:08AM Accepted Answer

    Hi

    Firstly some housekeeping:

    You still have an error in your script :

     console.log("noPermits ",noPermits); 
    

    should be  

    console.log("noPermits =" + noPermits); 
    

    Secondly, as I don't have access to your project I cannot see all the details but if I make a new project with exactly the same attributes, and place all of the items on the same Screen, then of course, if the user enters the data manually on the Screen the Total cost attribute will not show the value because all your code is in the mount key. Mount simply writes the HTML. There is no handling in your extension script for any kind of update key.

    Don't forget to manage the update key. As a simple (for demonstration only) example, put this in the update key:

      update: function(el) {
    				 document.getElementById("cost").value = control.getValue();
    				  var noPermits = interview.getValue("NoOfPermits");
    				  console.log("Value = " + control.getValue());
    				  console.log("noPermits = " + noPermits);
    
    
             }			
    

    And you will see:

    So, read the documentation on the update key and ensure it is implemented to your satisfaction. See https://documentation.custhelp.com/euf/assets/devdocs/unversioned/IntelligentAdvisor/en/Content/Guides/Developer_Guide/Web_Interviews/Styles_and_scripts/Extensions_for_custom_rendering_controls.htm as there are some things you need to think about.

    R

  • HarshadaK
    HarshadaK Member Posts: 12 Green Ribbon

    Hi Richard,

    After using update key, its working fine. Thank you