Part Two: Using Javascript to identify when to send a message
November 30, 2010
Using Javascript to identify when to send a message
In part one, we learned how to create custom output messages with Javascript. In part two, we will see how to create custom conditions that enable us to accurately determine when to send a message.
As in part one, we will incorporate a jscall into our condition field in order to be able to query fields and conditions that are not in our $L.file (current record). Many times, we have a necessity to base our notifications on more than simply the contents of the current record. An excellent example of this is based on whether any of the approvals for the current record have been denied. This example is the condition we will evaluate today.
1. Your condition will be constructed using the condition field. Since the condition field should evaluate to either a true or a false value, this means that any call to Javascript here must return a value of true or false
2. You’ll need to pass the current record(s) to the Javascript.
Replacing the condition: You want to replace the argument with:
jscall(“CustomNotificationHelpers.NotifyifDenied”, $L.file, $L.file.save)
The ScriptLibrary Function should look something like this:
function NotifyifDenied(record, oldrecord)
{
var fApprovalLog = new SCFile("ApprovalLog")
var filename = system.functions.filename(record)
var anyDenied = fApprovalLog.doSelect("file.name=""+filename+" and unique.key=""+record.number+" and current.phase=""+record.current_phase+"" and status="Denied"")
if (anyDenied == RC_SUCCESS)
{
return true
} else {
return false
}
}
This example showed how your notification line is no longer bound to the contents of the current record.
The sky is the limit in your ability to finely tune and control when to notify customers for records.
This is continued in Part 3.
Comments
Got something to say?
