Call Action Through JavaScript
How to Call Action Through JavaScript
Ans.
Step1: For this first you need to create one action with Two inputs and One output
FirstName , LastName as Inputs and FullName as Output.
Next add step as assign value and set FirstName and LastName to FullName
After Creating a JavaScript to call the action by using XRM toolbox
var execute_new_CustomJsAct_Request = {
// Parameters
entity: { entityType: "effizz_customjs", id: "4f948776-05b6-ee11-9078-6045bd726ef9" }, // entity
FirstName: "rtee", // Edm.String //change firstname value to fname
LastName: "merr", // Edm.String // change lastname value to lname
getMetadata: function () {
return {
boundParameter: "entity",
parameterTypes: {
entity: { typeName: "mscrm.effizz_customjs", structuralProperty: 5 },
FirstName: { typeName: "Edm.String", structuralProperty: 1 },
LastName: { typeName: "Edm.String", structuralProperty: 1 }
},
operationType: 0, operationName: "new_CustomJsAct"
};
}
};
Xrm.WebApi.online.execute(execute_new_CustomJsAct_Request).then(
function success(response) {
if (response.ok) { return response.json(); }
}
).then(function (responseBody) {
var result = responseBody;
console.log(result);
// Return Type: mscrm.new_CustomJsActResponse
// Output Parameters
var fullname = result["FullName"]; // Edm.String
}).catch(function (error) {
console.log(error.message);
});
In XRM Tool Box to check Result click on XHR and Inside the XHR Click on Move code later click on Execute code then automatically Result will come as FullName: Given Data (or) FullName: hari haraa
JavaScript :
function callActionUsingJavascript(executionContext) {
var formContext = executionContext.getFormContext(); //crm_name crm_lastname crm_fullname
var fname = formContext.getAttribute("effizz_name").getValue();
console.log(fname);
var lname = formContext.getAttribute("effizz_lastname").getValue();
console.log(lname);
//entity record guid
var userId = formContext.data.entity.getId();
console.log(userId);
var userIdstrFormat = userId.replace(/[{}]/g, "");
//the record which was came in currentrecordId /[{}]/g with these will replace and send it to ""
//Start Paste
var execute_new_CustomJsAct_Request = {
// Parameters
entity: { entityType: "effizz_customjs", id: userIdstrFormat }, // entity
FirstName: fname, // Edm.String
LastName: lname, // Edm.String
getMetadata: function () {
return {
boundParameter: "entity",
parameterTypes: {
entity: { typeName: "mscrm.effizz_customjs", structuralProperty: 5 },
FirstName: { typeName: "Edm.String", structuralProperty: 1 },
LastName: { typeName: "Edm.String", structuralProperty: 1 }
},
operationType: 0, operationName: "new_CustomJsAct"
};
}
};
Xrm.WebApi.online.execute(execute_new_CustomJsAct_Request).then(
function success(response) {
if (response.ok) { return response.json(); }
}
).then(function (responseBody) {
var result = responseBody;
console.log(result);
// Return Type: mscrm.new_CustomJsActResponse
// Output Parameters
var fullname = result["FullName"]; // Edm.String
formContext.getAttribute("effizz_fullname").setValue(fullname);
console.log(fullname);
}).catch(function (error) {
console.log(error.message);
});
//End Paste
}
After calling action using JavaScript, create web resource and the function on save of the form
Now go to the entity and create a record with first name and last name and save the record and check full name is coming or not
.png)
.png)
.png)






Comments
Post a Comment