Hi, hoping you can help.
I'm writing a jscript using sdk.rest.retrieverecord. I'm on an entity that has relationship with both Account and Contact.
On both Account and Contact I have a field called User Name. I'm using jscript to retrieve both these values and compare them.
I have a retrieverecords segment for both Account and Contacct and, from testing, I know it's working a bringing back the correct results.
But when i come to compare those two results, the variables have become undefined. I have moved bits of code around, defined the var's in different ways, but I can't get the comparison to work.
It's like the var's become undefined once the code moves on from the retrieverecord segment. This may be expected behaviour, but how do I get round this?
I've pasted the code below.... p.s. I tried to use the insert code function here, but it wouldn't work.
------------------------
var contact = Xrm.Page.getAttribute("xx_signedonbehalfofemployer").getValue();
var organisation = Xrm.Page.getAttribute("xx_employername").getValue();
var contactusername;
var organisationusername;
if (contact != null && organisation != null) {
SDK.REST.retrieveRecord(
contact[0].id,
"Contact",
"adx_identity_username",
null,
function (result) {
contactusername = result.adx_identity_username;
//alert(contactusername); // this alert returns the expected result
},
function (error) {alert(error.message);}
);
SDK.REST.retrieveRecord(
organisation[0].id,
"Account",
"xx_UserName",
null,
function (result) {
organisationusername = result.xx_UserName;
//alert(organisationusername); // this alert returns the expected result
},
function (error) {alert(error.message);}
);
alert(contactusername); // this alert throws up an error, contactusername is not defined
alert(organisationusername); // this alert throws up an error, organisationusername is not defined
//This is what I eventually want to do:
if (contactusername == null && organisationusername != null) {
alert("mismatch");
}
}
--------------------------
Thanks,
Pete.