Jump to content

Triggering Caspio Rules Programatically


Recommended Posts

Hi,

 

I have been customizing my Caspio App using custom Javascript, however, doing so does not trigger my rules.

 

Perhaps giving a mock scenario would better explain the situation:.

 

Given I have three Input fields: Alpha, Omega, and Sigma,

I have a Caspio Rule that says if Omega contains 'man', hide Sigma.

 

This works well when manually doing inputs directly to Omega. However, I have an on("input") listener that syncs the value of Alpha and Omega.

 

When I type 'Iron-man' on Alpha, it also appears on Omega, but Sigma is not being hidden.

 

I am hoping someone can help.

Many Thanks in advance.

 

 

Link to comment
Share on other sites

Hello @TroubleShooter,

 

It seems that Caspio's implementation on Rules only runs when the criteria element fires the input event (for text fields), and NOT when the value has been changed in the DOM.

 

In that case,  we can just programatically dispatch that event. See the example below. (I used jQuery to simulate the input event, but this implementation will work on vanillla (plain) Javascript)

<script type="text/javascript">

var omega = document.querySelector('#InsertRecordOmega')
var event = new Event('input', {
    'bubbles': true,
    'cancelable': true
});

$('#InsertRecordAlpha').on("input", function() {

omega.value = this.value;
omega.dispatchEvent(event);

});
</script>

 

It works for me. I am certain that you can make it work too ;).

Happy hacking!

 

Regards,

DN31337

Link to comment
Share on other sites

  • 1 year later...

Hi,

 

@DefinitelyNot31337,

 

I have a virtual calculated field as follows.

CASE WHEN 
--'[@authfield:No_Auto_Emails]' = 'Yes' AND
[@field:Status] = 'Completed' 

then

(select NotificationEmail from Caregivers where TimeAttendancePIN = '[@authfield:Nurse_UserName]' )




End

I have tried the following and didn't popup anything on the alert.

 

      // set status to complete
      $('input[name$="Status"]').val('Completed');
document.querySelector('input[name$="Status"]').dispatchEvent(new Event("change"));
   var Virtual1_textContent = $("span[id^='cbParamVirtual1']").text();
    alert(Virtual1_textContent); // <---- checking with an alert you get the right value

Any idea?

 

Thanks

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...