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

Yama2
Kilo Contributor

Hi @asifnoor ,

I tried your suggestion, it worked but the update rule on incident is still not firing. Also, how to check the field api name for custom fields?

To check field name of custom field, you can go to that table

system definition -> tables. open the table and underr columns you shall find the name of the column

OR

you can go to your table_name.do it opens the form. In that right click on your field and you can see the name of the field.

Is there a update BR on incident tabel as well? Because your BR is currently on sys_attachment table.

Yama2
Kilo Contributor

Yes, there is an update rule on incident as well as attachment because updating an attachment on incident record was not triggering the incident's update rule thus, i had to create a rule on attachment.

Can you share me the BR screenshot i.e. on incident table. 

Yama2
Kilo Contributor

@asifnoor ,
I think the event is getting fired now after some debugging but the issue now is i want to update the incident without updating the custom field. I would like to update attachments without creating any custom field on incident, is there a way to do that?