Quantcast
Channel: CRM Development Forum
Viewing all articles
Browse latest Browse all 888

Pull data from lookup record onto appointment using javscript

$
0
0

In CRM Online, I have a workflow which runs when an appointment is created. On the appointment I have a custom field for Client (lookup to account, called "exp_client") and a lookup to campaign (which has its own lookup to account, also called"exp_client").

Because I want to access fields in the client (account) record in the workflow, and it is too many levels to reach going through the campaign route (only 1 sub-entity) I was hoping to create some javascript which pulls the correct lookup through from the campaign record and place it on the appointment record.

I have come up with the following code which uses FetchUtil and is started by isNaN on the form load. As a reference, I have jquery and json running isNaN on form load too.

If anyone can point me in the right direction I'd greatly appreciate - my js skills aren't great!

// JScript source code
    var _oService;
    var _sOrgName = "";
    var _sServerUrl = Xrm.Page.context.getServerUrl();

function fillinclient() {

    var Search = Xrm.Page.getControl("regardingobjectid").getAttribute().getValue()[0];

    var sFetch = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' count='1'>" +"<entity name='campaign'>" +"<attribute name='exp_client' />" +"<filter type='and'>" +"<condition value='" + Search.id + "' operator='eq' attribute='campaignid' />" +"</filter>" +"</entity>" +"</fetch>";
    //alert(sFetch);

    _oService = new FetchUtil(_sOrgName, _sServerUrl);
    _oService.Fetch(sFetch, myConfigUpdate);
}

function myConfigUpdate(results) {
    Xrm.Page.getControl("exp_client").getAttribute().setValue(results.attributes["exp_client"]);
}


Viewing all articles
Browse latest Browse all 888


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>