I have set my business rule on sys_attachment table, so that when an attachment is updated on an incident record, i can fire my update incident rule to trigger operation on Incident table. I have tried below scripts but it is not working for me

Yama2
Kilo Contributor

condition = current.table_name == "incident"

When to run : After Insert/Update

(function executeRule(current, previous /*null when async*/ ) {
    var gr = new GlideRecord("incident");
    gr.addQuery("sys_id", current.table_sys_id);
    gr.query();
	gs.log("===>record exists", gr.next());
    while(gr.next()) {
		gs.log("===>record glide", gr);
		//fi = gr.getElement('isAttachmentUpdated'); 
		gr.setValue('isAttachmentUpdated', 'Updated'); //custom field isAttachmentUpdated
        gr.update();
    }

    // Add your code here

})(current, previous);

Note: I'm able to receive the "record exists" debug as "true" but not able to get the log inside while loop. Please help me understand what is the issue fix as the custom field (isAttachmentUpdated) on incident is also not getting updated.

 

 

1 ACCEPTED SOLUTION

Hello

If this has answered your question, kindly mark the comment as a correct answer so that the question is moved to solved list.

View solution in original post

20 REPLIES 20

Mike Patel
Tera Sage

double check the field name it might be u_isattachmentppdated

also change 

gs.log("===>record glide", gr);

to

gs.print("===>record glide", gr.number);

var gr = new GlideRecord("incident");
gr.addQuery("sys_id", current.table_sys_id);
gr.query();
if (gr.next()) {
    gs.print("===>record glide", gr.number);
    gr.setValue('isAttachmentUpdated', 'Updated'); //custom field isAttachmentUpdated
    gr.update();
}

Mike Patel
Tera Sage

We can not use gs.log() in scoped applications, We can use gs.info() , gs.warn()  ,gs.error(), gs.debug() in scoped applications for logging at different levels. 

 

The reason why gs.log() cannot be used for logging in scoped applications is  it is restricted to the global scope and not accessible from a private scope. When you are in a scoped application , your scope is bound in private to that application but gs.log() has been restricted to be accessible only at a global level kind of public but not at a private application level 

 

You can use alternate logging methods for using in scoped applications and that doesnot make much difference 

Log level | Description
error (gs.error) | Logs events that might still allow the application to continue running. Setting the log level for an application to error generates error messages only, but does not generate warn, info, or debug messages.
warn (gs.warn) | Logs potentially harmful events. Setting the log level for an application to warn generates error and warn messages, but does not generate info or debug messages.
info (gs.info) | Logs informational messages that describe the progress of the application. Setting the log level for an application to info generates info, warn, and error messages, but does not generate debug messages.
debug (gs.debug) | Logs informational events that are useful for debugging an application. Setting the log level for an application to debug generates info, warn, error, and debug messages.

asifnoor
Kilo Patron

Hi

you are using gr.next() twice bcoz of which the issue might be. Check like this.

(function executeRule(current, previous /*null when async*/ ) {
    var gr = new GlideRecord("incident");
    gr.addQuery("sys_id", current.table_sys_id);
    gr.query();
//	gs.log("===>record exists", gr.next());
    while(gr.next()) {
		gs.log("===>record glide", gr);
		//fi = gr.getElement('isAttachmentUpdated'); 
		gr.setValue('isAttachmentUpdated', 'Updated'); //custom field isAttachmentUpdated
        gr.update();
    }

    // Add your code here

})(current, previous);

Mark the comment as a correct answer and helpful if this helps.

Also use gs.info if you are in scoped application and cross verify the column name. if its custom column, check if its starting with u_.