function test(){
var lookupObj = Xrm.Page.getAttribute('new_divisionlookup');
var lookupObjValue = lookupObj.getValue();//Check for Lookup Value
if ( lookupObjValue != null) {
var lookupRecordGuid = lookupObjValue[0].id;
Xrm.WebApi.online.retrieveRecord("account", lookupRecordGuid, "?$select=new_classname2,new_classname3,new_classname4").then(
function success(result) {
var new_classname2 = result["new_classname2"];
var new_classname3 = result["new_classname3"];
var new_classname4 = result["new_classname4"];
var setC2 = Xrm.Page.getAttribute('new_cname1').setValue(new_classname2);
var setC3 = Xrm.Page.getAttribute('new_cname2').setValue(new_classname3);
var setC4 = Xrm.Page.getAttribute('new_cname3').setValue(new_classname4);
var addNewOption = function (executionContext) {
var field = executionContext.getFormContext().getControl('new_ttoptionset');
if (field == null || field != null )
{
var new_classname222 = Xrm.Page.getAttribute('new_cname1').getValue();
var new_classname223 = Xrm.Page.getAttribute('new_cname2').getValue();
var new_classname224 = Xrm.Page.getAttribute('new_cname3').getValue();
var obj={};
obj['text']= new_classname222 ;
obj['value']=10;
field.addOption(obj);//add to option set field
}
}
},
function(error) {
Xrm.Utility.alertDialog(error.message);
}
);
}
else
var lookupObjValue111 = Xrm.Page.getAttribute('new_cname1').setValue(null);
var lookupObjValue122 = Xrm.Page.getAttribute('new_cname2').setValue(null);
var lookupObjValue133 = Xrm.Page.getAttribute('new_cname3').setValue(null);
}
new_ttoptionset is the field where i want to add values from new_classname2,3 and 4, but the above code is not successful of doing so.