Tag Cloud

CRM 2011 (161) CRM 4.0 (144) C# (116) JScript (109) Plugin (92) Registry (90) Techpedia (77) PyS60 (68) WScript (43) Plugin Message (31) Exploit (27) ShellCode (26) FAQ (22) JavaScript (21) Killer Codes (21) Hax (18) VB 6.0 (17) Commands (16) VBScript (16) Quotes (15) Turbo C++ (13) WMI (13) Security (11) 1337 (10) Tutorials (10) Asp.Net (9) Safe Boot (9) Python (8) Interview Questions (6) video (6) Ajax (5) VC++ (5) WebService (5) Workflow (5) Bat (4) Dorks (4) Sql Server (4) Aptitude (3) Picklist (3) Tweak (3) WCF (3) regex (3) Config (2) LINQ (2) PHP (2) Shell (2) Silverlight (2) TSql (2) flowchart (2) serialize (2) ASHX (1) CRM 4.0 Videos (1) Debug (1) FetchXml (1) GAC (1) General (1) Generics (1) HttpWebRequest (1) InputParameters (1) Lookup (1) Offline Plug-ins (1) OutputParameters (1) Plug-in Constructor (1) Protocol (1) RIA (1) Sharepoint (1) Walkthrough (1) Web.config (1) design patterns (1) generic (1) iframe (1) secure config (1) unsecure config (1) url (1)

Pages

Saturday, January 26, 2013

get/set lookup value in CRM 4

 
/* Jscript */


// get lookup
gLookupGetValue = function (objLookup){
/*
This function is used read a value from lookup field
This function requires the following parameters:
objLookup: reference to the lookup object e.g. crmForm.all.productid
Returns: Array
[0] = returns lookup GUID
[1] = returns lookup text value
[2] = returns lookup entity type name (e.g. account)
[3] =//returns lookup entity type code (e.g. 1=account), 2=contact, etc)
Example:
var name = gLookupGetValue(crmForm.all.accountid)[1]
Author: GP
*/

var lookupItem = new Array;
var arr = new Array();
arr[0] = ""; //returns lookup GUID
arr[1] = ""; //returns lookup text value
arr[2] = ""; //returns lookup entity type name (e.g. account)
arr[3] = ""; //returns lookup entity type code (e.g. 1=account), 2=contact, etc)
// Get a reference to the lookup control on the form.
lookupItem = objLookup.DataValue;

// If there is data in the field, show it in a series of alerts.
if (lookupItem != null){
// Return the GUID of the lookup.
arr[0] = lookupItem[0].id;
// Return the text value of the lookup.
arr[1] = lookupItem[0].name;

// Return the entity type name of the lookup.
arr[2] = lookupItem[0].typename;

// Return the entity type code of the lookup.
arr[3] = lookupItem[0].type;
}
return arr;
}
// set lookup
gLookupSetValue= function(objID, objText, objType){
/*
This function is used set a defaultvalue in a lookup field and requires the following parameters:
objID: ID of the record
objText: Text or Name of the record
objType: Entity code or Entity Name
Returns: lookup object
Designed by: Geron Profet
Example 1: retrieve based on entity type code
var defaultpricelevelname = 'Standard';
var defaultpricelevelid = gGetValue('pricelevelid','pricelevel','name',defaultpricelevelname)[2];
crmForm.all.pricelevelid.DataValue = gLookupSetValue(defaultpricelevelid, defaultpricelevelname, 1022);

Example 2: retrieve based on entity type name
crmForm.all.pricelevelid.DataValue = gLookupSetValue(defaultpricelevelid, defaultpricelevelname, 'pricelevel');
*/

// Create a lookupItem to store the values that you want to set to a target lookup control.
var lookupData = new Array();
var lookupItem= new Object();

//Set the id, name and typecode or typename properties to the object.
lookupItem.id = objID;
lookupItem.name = objText;

//if objType is not numeric, assume the entitytypename is passed
if (!isNaN(objType)){
lookupItem.type = objType;
} else {
lookupItem.typename = objType;
}

// Add the object to the array and return the lookupItem that you just created.
lookupData[0] = lookupItem;
return lookupData;
}