The CreatorCon Call for Content is officially open! Get started here.

Is current.hasAttachments valid?

tahnalos
Kilo Sage

I have a business rule that has the following condition:

!(current.hasAttachments())

As you can imagine, this business rule is supposed to run if it detects an attachment is not linked to a ticket.   I THOUGHT it was working earlier, but only found out that someone had already put in a Has Attachment Field previously, and there was a second business rule looking at that field.   Initially, I thought that the second business rule was redundant so I deactivated it.   This business rule no longer fires off, and I suspect that current.hasAttachments is actually not valid.

Can someone confirm if this is the case?

Thanks

3 REPLIES 3

Justin Abbott
Giga Guru

current.hasAttachments() should work. I ran your use case through a test in my developer instance and !(current.hasAttachments()) fires if the record does NOT have any attachments.


Yeah, I just looked at it again.   The record apparently has to be modified so that the business rule will fire.   Adding an attachment does not trigger a record as "updated".



This poses an issue regarding a UI action which is supposed to kick off a process.   The problem is that the process should only be kicked off when an attachment is active in the system.   If one does not add an attachment, it should go through the UI action, which performs a current.update(), which should kick off the business rule, but since the record was not modified, the business rule does not trigger.



Is there any way to "force" a business rule to run?



Thanks


You could maybe write a business rule on sys_attachment that queries the table the attachment is being attached to and force it to update.



Something like...



var gr = new GlideRecord(current.getValue('table_name'));


if (gr.get(current.getValue('table_sys_id'))) {


      gr.setValue('SOME_FIELD_OF_YOUR_CHOICE', 'SOME VALUE OF YOUR CHOICE');


      gr.update();


}