Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 9244

Get Record In Entity Where Option Set Is Equal To A Value.

$
0
0

I have 1 entity called "JobForm", and another entity called "LabourRates".

The "JobForm" entity has a lookup to "LabourRates" which has the name field as an amount. For example, labour rate of £10.00.

In the "LabourRate" entity there is an optionset with 2 values, "current" and "outdated".

I am trying to create a plugin which on creation of a "JobForm" the "LabourRate" lookup field will automatically get populated with the record in "LabourRates" where the optionset is "current".

How can i do this...

The user should be able to update the labour rate, and older records must then be set as outdated and new one to current.

Here is what i have so far.


function setCurrentLabourRate() {

	if(Xrm.Page.ui.getFormType() == 1) {
		getCurrentLabourRate();
	}

}
function getCurrentLabourRate() {
	
		var serverUrl = Xrm.Page.context.getServerUrl();
		
		var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";		
		var odataSetName = "c2_labourrateSet";
		var odataSelect = serverUrl + ODATA_ENDPOINT + "/" + odataSetName;
		$.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: odataSelect,
        beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
        success: function (data, textStatus, XmlHttpRequest) {
            var result_labourrate = data.d;
			var labourRateStatusCurrent = result_labourrate.c2_Status.Value; //c2_status is the optionset
			if(labourRateStatusCurrent = "745,670,000") // Value of the optionset which equals "Current"
			{
				var lookupData = new Array();
				var lookupItem = new Object();
				lookupItem.id = ????? 
				lookupItem.typename = "c2_labourrate"; // Is the lookup in "JobForm"  
				lookupItem.name = ?????
				lookupData[0] = lookupItem;	
				Xrm.Page.getAttribute("c2_labourrate").setValue(lookupData); // Set the lookup in "JobForm";
			}
	}

]

2 Problems:

1. I am unable to get the lookup id and name for the record i am on where the status is current so i can then set it to the labour rate lookup in job form.

2.  I need some seperate code to run on change of the optionset is labour rates, that when the option set gets changed  to "current". All other records in the entity have the optionset changed to "outdated".



Viewing all articles
Browse latest Browse all 9244

Trending Articles