Skip to main content

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

Hi @MWAMAITTEAM 

Try lower case ‘start_work_flow’ instead of ‘START_WORK_FLOW’

var response = executePerform('start_work_flow',requestID);
if(response.message != null && response.message != '')
{
alert(response.message);
}

Cheers!


Hi Shneor,

Thanks for coming back to me. I have tried as you suggested with the client script below.

//Created by Barry 08/10/2024

var RequestId = getControlValue('request','request_id');

var response = executePerform('start_work_flow',requestID);
if(response.message != null && response.message != '')
{
alert(response.message);
}

However when I execute in client scrips to check syntax I get the error below.

 

Can you see any issue with the code?

Thanks,

Barry


Hi @MWAMAITTEAM 

I think that your variable names should match.

requestID ↔️ RequestId

Cheers!


Hi @Shneor Cheshin 

Unfortunately same error with variable name casinng corrected.

// Created by Barry 08/10/2024
var RequestId = getControlValue('request','request_id');

var response = executePerform('start_work_flow',RequestId);
if(response.message != null && response.message != '')
{
alert(response.message);
}

Regards,

 

Barry


Hi @MWAMAITTEAM 

executePerform expects an array of parameters.

Try the following

var RequestId = getControlValue('request','request_id');
var params = {};
params.request_id = RequestId;
var response = executePerform('start_work_flow',RequestId);
if(response.message != null && response.message != '')
{
​​​​​​​alert(response.message);
}

Cheers!


Thanks @Shneor Cheshin,

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.

 

Regards,

Barry


@MWAMAITTEAM 

My bad, I did not replace it with params

var RequestId = getControlValue('request','request_id');
var params = {};
params.request_id = RequestId;
var response = executePerform('start_work_flow',params);
if(response.message != null && response.message != '')
{
​​​​​​​alert(response.message);
}

Cheers!


Hi @Shneor Cheshin - good point. I didnt notice that, however still the same issue after that change.

 

 

Regards,

Barry


Hi @MWAMAITTEAM 

Not sure what to say. We can try another syntax

var RequestId = getControlValue('request','request_id');
//var params = {};
//params.request_id = RequestId;
var response = executePerform('start_work_flow',{request_id: RequestId});
if(response.message != null && response.message != '')
{
​​​​​​​alert(response.message);
}


Cheers!

Hi Shenor,

This time I again have the Unexpected Token error.

 

Regards,

Barry


@MWAMAITTEAM 

Did you try running this in Webclient? Or is it just the debug screen?

If not, please try a real scenario from the Webclient.

Cheers!


Hi Shenor,

I have been on annual leave. Back today so will try this week and let you know!

Regards,

Barry


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.

 


Hi Samlk,

Your version of the script works and I have associated it with the click event on the button and tested successfully.

Thanks for your help with this.

Regards,

Barry


Reply