ProApp Designer - Release 14.10 (Package 27)

ApplyMethod

It allows you to invoke any server method defined on the server side. All parameters required by the method must be packaged in JSON format when making the call.

Example 1: Calling serverMethod by passing parameters and getting item in the response

Client Code:
const parmObj = { partId: “FB3CBC878D5747DEBF25508B23CF6B5B” };
const resultObj = appStudioWizard.applyMethod(“methodName”, parmObj);

Server Method:
string partId = this.getProperty(“partId”);
if(partId == null) throw new Exception(“Please provide partId.”);

Item partItem = this.getInnovator().newItem(“Part”, “get”);
partItem.setID(partId);
partItem = partItem.apply();
if(partItem.isError() && partItem.isEmpty()) throw new Exception(“No items found.”);

return partItem;

Example 2: Calling serverMethod by passing json and getting json in the response

Client Code:
const partDetails = { classification: “Component”, make_buy: “Make” };
const body = { request: JSON.stringify(partDetails) };
const resultObj = appStudioWizard.applyMethod(“methodName”, body);

Server Method:
string partDetailsString = this.getProperty(“request”);
var partDetails = new Newtonsoft.Json.Linq.JObject();
if (partDetailsString == null) {
throw new Exception(“Please provide partDetails.”);}
else { partDetails = Newtonsoft.Json.Linq.JObject.Parse(partDetailsString);}

string classification = partDetails.SelectToken("$.classification”)?.ToString();
string make_buy = partDetails.SelectToken("$.make_buy”)?.ToString();
Item query = this.getInnovator().newItem(“Part”, “get”);
query.setAttribute(“select”, “item_number, name, classification, make_buy”);
query.setProperty(“classification”, classification);
query.setProperty(“make_buy”, make_buy);
var partItems = query.apply();
if(partItems.isError() && partItems.isEmpty()) throw new Exception(“No items found”);

return partItems;
Output:
[
{
“classification": “Component”,
“make_buy": “Make”,
“name": “Trunk”,
“item_number": “004",
“itemtype": “4F1AC04A2B484F3ABA4E20DB63808A88"
},
...]