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

Business Rule


-------------------------


When - Display


Query - true



Script:


(function executeRule(current, previous /*null when async*/) {


// Add your code here


  g_scratchpad.hasAttachments = current.hasAttachments();


  gs.addInfoMessage("g_scratchpad.hasAttachments"+g_scratchpad.hasAttachments);


})(current, previous);



Client script


---------------------------------


type :Onload



function onLoad() {


    //Type appropriate comment here, and begin script below


  alert('g_scratchpad.hasAttachments : '+g_scratchpad.hasAttachments);



}


This is working fine.See the attached screenshot


Capture3.PNG


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


Hi Mihir,


I have used your code and this is working fine.


thank u



Soumen


Hi Soumen,



FYI .. as per best practice don't write Gliderecord on client side, call includescript for that .



Regards,


Harish Murikinati.


Hi Soumen,


Glad to hear that it works for you.


Please mark my solution as correct for reference of other users.


Thanks,


Mihir