RE: How to trigger a workflow without saving
Hi, yeah I agree with Guido Preite
You should write a custom webresource JavaScript and listening in OnChange event in the Incidet Form in the field Account.
here an configurable example how it could be done note: It also could be improve to handle n fields but for the sake of the task you need, it could work
function setAccountInfo(context){
//config
var caseField1LogicalName = "THE NAME OF YOUR FIELD ON CASE";//e.g: new_field1
var caseField2LogicalName = "THE NAME OF YOUR FIELD ON CASE";//e.g: new_field2
var accountFields = "ALSO LOGICAL NAME ACCOUNT FIELD SEPARATED BY COMMA"; //e.g accountfield1,accountfield2, if is a lookup the fortmat will be _FIELDNAME_value e.g _new_accountfield_value
var customerLogicalName = "customerid"; //I'm assuming the Case Account the field is 'customerid'
var formContext = context.getFormContext();
var customerId = formContext.getAttribute(customerLogicalName).getValue();
if(!customerId)
return;
customerId = customerId[0].id.replace(/[{|}]/g,"");
var entityName = "account";
var query = `?$select=${accountFields}&$filter=accountid eq ${customerId}`;
Xrm.WebApi.retrieveMultipleRecords(entityName,query).then(
function(result){
var fields = accountFields.split(",");
var res1 = formattValues(result,fields[0]);//pass true if its a lookup
var res2 = formattValues(result,fields[1],true);//it's prepared to support lookup values
setField(formContext.getAttribute(caseField1LogicalName),res1);
setField(formContext.getAttribute(caseField2LogicalName),res2);
},
function(err){
console.log(err);
}
);
}
function formattValues(result,fieldLogicalName,isLookUp = false){
var value = result.entities[0] || null;
if(value){
if(!isLookUp)
value = value[field1LogicalName];
else
value = setLookUp(value,fieldLogicalName)
}
return value;
}
function setLookUp(objectResponse,fieldLogicalName){
var lookupValue = [];
var value = {};
value.id = objectResponse[fieldLogicalName];
value.name = objectResponse[fieldLogicalName "@OData.Community.Display.V1.FormattedValue"];
value.entityType = objectResponse[fieldLogicalName "@Microsoft.Dynamics.CRM.lookuplogicalname"];
lookupValue.push(value);
return lookupValue;
}
function setField(control,value){
if(control)
control.setValue(value);
}
now you just need to add it to your form and pass the execution context to it.
Hope it help, regards.
if it was helpful please consider mark it as an answer