Saturday, 4 February 2012

soap service javascript

http://community.dynamics.com/product/crm/crmtechnical/b/xrmavanade/archive/2010/07/18/updated-crmservice-js.aspx


            var service = new crmSOAPService(orgUniqueName, server);
                        var columnset = ['attributename'];
                        var setpinstance = service.Retrieve("entityname", selectedIds[0], columnset);
                        setpinstance.attributes["attibutename"];

setting lookup/entityreference field
var lookupvalue = [{ id: selectedIds[0], name: "name value", entityType: "entityname"}] ;

Xrm.Page.getAttribute("attriubtename").setSubmitMode("always");
Xrm.Page.getAttribute(" attriubtename ").steptocloseLookup.setValue( lookupvalue  );


---------------
use advance find to generate fetch xml


 
      var orgUniqueName = context.getOrgUniqueName(); 
      var server = Xrm.Page.context.getServerUrl().replace("/" + orgUniqueName, "");


      var service = new crmSOAPService(orgUniqueName, server);
   
      var fetchResult = service.Fetch(fetchXml);
      var  longestInstance  = null;

        if (fetchResult.length > 0) {
            var prevDiff = 0;

            for (instance in fetchResult) {

                var startDateString = fetchResult[instance].attributes.new_startdate.value; //"2012-01-30T00:00:00-00:00"
                var endDateString = fetchResult[instance].attributes.new_enddate.value;

                var startDate = new Date(startDateString.substring(0, 10).replace(/-/g, '/')); //Mon Jan 30 00:00:00 UTC 2012 Object
                var endDate = new Date(endDateString.substring(0, 10).replace(/-/g, '/'));

                var diff = Math.abs(endDate - startDate);

                //alert("GetLongestStep:diff" + diff);

                if (prevDiff < diff) {
                    prevDiff = diff;
                    longestInstance = fetchResult[instance];
                }
            }
        }

------------

No comments:

Post a Comment