Running Trigger from Custom button

Posted by intekra on 24-Jun-2016 15:48

Hi All,

I am trying to generate my invoice word document by a custom button on my invoice object. Not having much luck.

1) I created a template document that works perfectly under preview

2) I created a "create Template document" Trigger

3) I created a button called "Generate Invoice" and used this code to run the trigger..

rbf_runTrigger("Invoice28", {!id}, "GenerateInvoiceDoc", false, , )

But when I click the button nothing happens, can someone steer me in right direction..

Thanks

Jeff

All Replies

Posted by Chandrasekhar Gontla on 24-Jun-2016 22:44

Hi intekra,

I have tried the steps that you mentioned above and able to get the generated doc template.

> My button definition

rbf_runTrigger("emp6", "{!id}", "LpAOUu65TmiZWInmLFTvfQ", false, callback, false);

> Added the button in record details page.

Note: If you add the button to new record page, then the above script won't execute as id won't be resolved

> Clicked on the button

> Refresh the page

> Document template has been attached to file upload filed (this is configured in trigger definition)

Thanks and Regards,

Chandu.

Posted by intekra on 25-Jun-2016 10:24

Hi Chandu, Thanks for the advice, however I tried and the button still doesn't work.

The create document trigger does work if i use timing and edit and save the record. But I would like it to generate the file and save on the button click... Here is my button code..

rbf_runTrigger("Invoice28", "{!id}", "cPJe0SogQzq8uNsNqn1EqQ", false, callback, false);

Am I missing something before or after this snip of code on the button?

Also, is there anyway to automatically refresh the record after the button is clicked to generate the document?

Thanks

Jeff

Posted by Mohammed Siraj on 27-Jun-2016 01:50

The second argument in this function call is incorrect i.e. "{!id}"

i.e. rbf_runTrigger("Invoice28", "{!id}", "cPJe0SogQzq8uNsNqn1EqQ", false, callback, false);

"{!id}" is a Rollbase token that is evaluated at runtime when used to program server-side behavior i.e. triggers,templates etc.

However, on client-side you need to pass the static value while invoking the function. In an object view page, you can retreive the same using client-side SDK that is:

function getRecordId(){

 var recordId= -1;

 try{

    recordId = rbf_getPageContext().getObjectRecord()['id'];

 }

 catch(err){

 }

 return recordId;

}

rbf_runTrigger("Invoice28", getRecordId(), "cPJe0SogQzq8uNsNqn1EqQ", false, callback, false);

Posted by Chandrasekhar Gontla on 27-Jun-2016 02:47

Hi intekra,

I understood the problem.

If you are using callback function inside rbf_runTrigger() method, then you need to define that function. Otherwise, you will get the error saying 'VM11980:2 Uncaught ReferenceError: callback is not defined' in the browser console.

Note: Click on F12 to launch browser console and then execute the button. You can find the error.

To avoid the above error, you need to pass null to callback parameter like below

rbf_runTrigger("Invoice28", "{!id}", "cPJe0SogQzq8uNsNqn1EqQ", false, null, false);

And, you can refresh the page automatically using below code.

setTimeout(function (){location.reload(true);}, 3000);// This will refresh the page after 3 seconds

And, if you want to use callback method, you can do it in this way.

rbf_runTrigger("emp6", "{!id}", "LpAOUu65TmiZWInmLFTvfQ", false, callback, false);

function callback(status){

 console.log(status);

 setTimeout(function (){location.reload(true);}, 3000);

}

Thanks and Regards,

Chandu.

This thread is closed