Tuesday, 12 April 2016

How to attach BI Publisher Report to an email?[Answered]

In the below example, we are generating reports using PS Query(we can use XML too).


/*General code to print BI Publisher Report*/
import PSXP_RPTDEFNMANAGER:*;

/* get report definition object */
&oRptDefn = create PSXP_RPTDEFNMANAGER:ReportDefn (&sRptDefn);
&oRptDefn.Get();
&oRptDefn.OutDestination = "/" | GetCwd(); /*We can change this path, if needed*/
/* fill query runtime prompt record */
&rcdQryPrompts = &oRptDefn.GetPSQueryPromptRecord();
If Not &rcdQryPrompts = Null Then
  &oRptDefn.SetPSQueryPromptRecord(&rcdQryPrompts);
End-If;
&oRptDefn.ProcessInstance = &prcsInstId;
/*generate report*/
&oRptDefn.ProcessReport (&sTmpltID, &sLangCd, &AsOfDate, &sOutFormat);
&URL_ID = "record://RECORD_NAME"; /*Create URL ID before proceeding, use this link for the steps to URL ID */
&oRptDefn.ReportFileName = "Report_Name"; /*We are changing the name of the report just make it possible to locate it*/
&filename = "Report_Name"|"."|&sOutFormat; /*Adding the extension of the file*/
&source_file = &oRptDefn.OutDestination | &filename;
&return = PutAttachment(&URL_ID, &filename, &source_file);
/*publish report */
&oRptDefn.Publish(&sPrcsServerName,"",&sFolder, &prcsInstId); /*&sPrcsServerName and &sFolder can be "" (i.e. blank) and &prcsInstId is process instance of your process*/
/*As now we have the path for the report (i.e. &source_file), we can now use this to add this report as an attachment in our email, as shown below code*/
&dest_file = &source_file; 
/*SendMail() can directly access this file if application server and ftp server are at same location. If they are at different location, use GetAttachment() to get file from ftp server to application server and then mention the path of application server*/
&RET =SendMail(&MAIL_FLAGS, &MAIL_TO, &MAIL_CC, &MAIL_BCC,&MAIL_SUBJECT, &MAIL_TEXT, &dest_file, &filename,&MAIL_FROM,&MAIL_SEP,&CONTTYPE,&REPLYTO, &SENDER);

Sunday, 22 March 2015

Hiding rows in grid/Scroll Area for specific conditions



Local Rowset &rs;
Local Number &i,&k;
&rs=getlevel0()(1).getrowset(Scroll.YourRecordName);

&i=1; 
&k=0;
&rs.showAllRows();
while (&i+&k) <=&rs.activerowcount

/* Suppose below condition is to hide that particular row*/
if &rs(&i).YourRecordName.FieldName.value="Whatever" Then 
&rs(&i).visible=false;
&k=&k+1;
else
&i=&i+1;
end-if;

end-while;

Monday, 2 March 2015

Generating new sequence number while inserting new row in a grid/Scroll area.

Write the below code in row insert or row init event (preferably in row insert) of the record peoplecode or the record field peoplecode.
Local Rowset &rs;
Local number &max;
&rs=getlevel0()(1).getrowset(Scroll.YourRecordName);

rem Below loop is to find the max sequence number in your grid;
&max=0;
for &i=1 to &rs.activerowcount
 if &max<&rs(&i).YourRecordName.SEQNBR.value then
&max=&rs.YourRecordName.SEQNBR.value;
end-if;

end-for;

rem Assigning Sequence number to the new row;

if none(&rs(CurrentRowNumber()).YourRecordName.SEQNBR.value) then
&rs(CurrentRowNumber()).YourRecordName.SEQNBR.value=&max+1;
end-if;