Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How do I check file attachment in a form by clientscript

rock2freedom
Mega Contributor

How do I check file attachment in a form by clientscript

1 ACCEPTED SOLUTION

Mihir Mohanta
Kilo Sage

Hi Soumen,


No need to create a separate business rule for this.


Just query to sys_attachment table.


Please try below client script.



var sysid = g_form.getUniqueValue();


  var attach = new GlideRecord('sys_attachment');


  attach.addQuery('table_sys_id',sysid);


  attach.query();


  if(attach.next()){


  alert("form contains attachment");


  }




Please mark it as Helpful/Correct according to its impact.




Thanks,


Mihir


View solution in original post

11 REPLIES 11

HarshTimes
Kilo Sage

Hi Soumen,


You can do this using a scratchpad variable.



create a on display business rule that will setup a scratchpad variable


g_scratchpad.hasAttachments = current.hasAttachments();



Now, use this scratchpad variable in your client script to check whether related record has attachment or not.



if (g_scratchpad.hasAttachments)


      // put your code


else


      // put your code




-Harsh


when I am using g_scratchpad.hasAttachments in clientscript its displaying 'undefined' so its executing else pert of the code always


have you created the business rule . Update the business rule to before query and then try the client script.


Hi Harsh,



Yes I have written business rule and Update it before write the client script.the g_scratchpad object is available in client script but it doe not find .hasAttachments .So it becomes undefined.




Thanks,


Soumen