How to generate a pdf from a form and send it to another table

suprakash
Giga Expert

Suppose I am entering some data in a form of table u_candidate_details   and when i submit or save the form a record will be inserted in table u_candidate_database and a pdf attachment will be added on the record that was created on table u_candidate_database . the attachment will be pdf of the form view u_candidate_details  

1 ACCEPTED SOLUTION

nayanawadhiya1
Kilo Sage

Hey Suprakash,



Write a INSERT BUSINESS RULE -



var gr = new GlideRecord ('u_candidate_database');


gr.addQuery(Filter_condition);


gr.query();


if(gr.next())


{


var rm = new sn_ws.RESTMessageV2();
      rm.setHttpMethod('GET');
      var url = gs.getProperty("glide.servlet.uri") + current.getTableName()+ '.do?PDF&sys_id=' + current.sys_id;
      rm.setEndpoint(url);
      rm.setBasicAuth(gs.getProperty('glide.user.userid'), gs.getProperty('glide.user.password'));
      rm.saveResponseBodyAsAttachment(gr.getTableName(),gr.sys_id,current.number+".pdf");
      var response = rm.execute();

}


View solution in original post

41 REPLIES 41

Hi Nayan,

 

I used this code to generate pdf in business rule after insert, But it is not working

 

find_real_file.png

 

Thanks,

Harshitha SR

Lisha Kamsu
Tera Expert

Hi,

I also got the same type of requirement, i.e create a PDF of Task and assign to REQ table.

I have create UI Action on server side. 

 

var rm = new sn_ws.RESTMessageV2();

rm.setHttpMethod('get');
var url = gs.getProperty("glide.servlet.uri") + current.getTableName()+ '.do?PDF&sys_id=' +current.sys_id;
rm.setEndpoint(url);
//gs.addErrorMessage("Hi am from Ui Actin" + url);

rm.setBasicAuth("Lisha Kamsu","Lish@6996");
//rm.setBasicAuth(gs.getProperty('glide.user.userid'), gs.getProperty('glide.user.password'));
var l = current.request_item;
var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id',l);
gr.query();
//var count = 0;
while(gr.next()){
//count++;
}
var s = "sc_request";
var attRec = new GlideRecord('sys_attachment');
attRec.addQuery('table_sys_id', gr.request);
attRec.query();
//var count = 0;
while(attRec.next()){
//count++;
//var z = gr.getDisplayValue('request');
//gs.addErrorMessage("kdkf" + z);
var y = current.number + ".pdf";
if(attRec.file_name == y ){
//gs.addErrorMessage("Sucessfull");
attRec.deleteRecord();
}
}

 

rm.saveResponseBodyAsAttachment(s,gr.request,current.number+".pdf");
//gs.addErrorMessage(" 13" + s + ""+ count + "ki"+ z);
var response = rm.execute();
//gs.addErrorMessage(" 14");
action.setRedirectURL(current.getTableName()+".do?sys_id="+current.sys_id);

 

If any issue , please feel free to reach out me. 

 

Regards,

LishaKasmu