I am attempting my first client script. We curently have a button on the Request screen that runs the START_WORK_FLOW MPM on the Smart Client.
This does not work in the web client as I am told it must be triggered via a Client Script. I have attempted a basic script to do this as shown below.
However it errors as follows.
The syntax I have used I think mirrors what I have seen in other examples. Any help would be appreciated.
Thanks,
Barry
Best answer by SAMLK
Hi Shenor,
This time I again have the Unexpected Token error.
Regards,
Barry
Hi @MWAMAITTEAM ,
Looks like the issue is coming from the “response.message” syntax here as the mpm does not return a message element in a successful response (it returns a taskRow). It should have a general condition check with (response != null && response !=’ ’)
Hence suggesting you to alter your code as below.
var RequestId = getControlValue('request','request_id'); var params = {}; params.request_id = RequestId; var response = executePerform('start_work_flow',params); if(response != null && response != '') { if (response.$type == 'ErrorResponse') { alert(response.message); //will throw a message element only if an error was thrown during the mpm execution } else { alert("A new task with task id "+response.task.task_id+" has been created!"); // will generate a taskRow response if the mpm is successful (you can use any valid task field here for the response). } }
Also, suggesting you not to test this on the smart client’s client script debugger as it’s likely to throw syntax exceptions. Make sure to associate your script on the button click event using the UI designer and then directly test it on the web client.
We had tried the parameter approach yesterday but ran into issues with that. When I paste in your code and run it in the client scripts screen we get the error that a ; is missing though on looking at your code it deos not seem to be missing.
This time I again have the Unexpected Token error.
Regards,
Barry
Hi @MWAMAITTEAM ,
Looks like the issue is coming from the “response.message” syntax here as the mpm does not return a message element in a successful response (it returns a taskRow). It should have a general condition check with (response != null && response !=’ ’)
Hence suggesting you to alter your code as below.
var RequestId = getControlValue('request','request_id'); var params = {}; params.request_id = RequestId; var response = executePerform('start_work_flow',params); if(response != null && response != '') { if (response.$type == 'ErrorResponse') { alert(response.message); //will throw a message element only if an error was thrown during the mpm execution } else { alert("A new task with task id "+response.task.task_id+" has been created!"); // will generate a taskRow response if the mpm is successful (you can use any valid task field here for the response). } }
Also, suggesting you not to test this on the smart client’s client script debugger as it’s likely to throw syntax exceptions. Make sure to associate your script on the button click event using the UI designer and then directly test it on the web client.