Skip to main content
Solved

Client Script Perform MPM

  • October 8, 2024
  • 14 replies
  • 113 views

Forum|alt.badge.img+7

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.

 

14 replies

Shneor Cheshin
Superhero (Employee)
Forum|alt.badge.img+28
  • Superhero (Employee)
  • October 8, 2024

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!


Forum|alt.badge.img+7
  • Author
  • Sidekick (Customer)
  • October 9, 2024

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


Shneor Cheshin
Superhero (Employee)
Forum|alt.badge.img+28
  • Superhero (Employee)
  • October 9, 2024

Hi @MWAMAITTEAM 

I think that your variable names should match.

requestID ↔ RequestId

Cheers!


Forum|alt.badge.img+7
  • Author
  • Sidekick (Customer)
  • October 10, 2024

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


Shneor Cheshin
Superhero (Employee)
Forum|alt.badge.img+28
  • Superhero (Employee)
  • October 10, 2024

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!


Forum|alt.badge.img+7
  • Author
  • Sidekick (Customer)
  • October 10, 2024

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


Shneor Cheshin
Superhero (Employee)
Forum|alt.badge.img+28
  • Superhero (Employee)
  • October 10, 2024

@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!


Forum|alt.badge.img+7
  • Author
  • Sidekick (Customer)
  • October 11, 2024

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

 

 

Regards,

Barry


Shneor Cheshin
Superhero (Employee)
Forum|alt.badge.img+28
  • Superhero (Employee)
  • October 14, 2024

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!

Forum|alt.badge.img+7
  • Author
  • Sidekick (Customer)
  • October 14, 2024

Hi Shenor,

This time I again have the Unexpected Token error.

 

Regards,

Barry


Shneor Cheshin
Superhero (Employee)
Forum|alt.badge.img+28
  • Superhero (Employee)
  • October 14, 2024

@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!


Forum|alt.badge.img+7
  • Author
  • Sidekick (Customer)
  • October 21, 2024

Hi Shenor,

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

Regards,

Barry


SAMLK
Hero (Partner)
Forum|alt.badge.img+14
  • Hero (Partner)
  • Answer
  • October 22, 2024

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.

 


Forum|alt.badge.img+7
  • Author
  • Sidekick (Customer)
  • October 28, 2024

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