locked
Gross Profit Calculation and Field Mapping RRS feed

  • Question

  • Hi
    I am trying to enable some Gross Profit calculations in CRM.
    So far I have created a field on the Product Form called 'GP'
    I have placed an onload calculation which takes the Price away from the standard cost and populating the GP field. This is giving the GP.
    So far so good.

    I would like to map this right through to Quote Product, so the quote product shows total GP (for example if the GP on Item A is £1 then if the quantity is 5, the total GP for the quote on this product is £5).

    Then, the quote should show a total of all GP calculations:
    GP at product level
    GP at Quote product level
    GP at Quote level

    Does this make sense?
    Rob
    www.crmconsult.info www.chorusit.com
    Wednesday, August 5, 2009 1:39 PM

Answers

  • This is code I use to bring a value from the product (new_supportvalue) down to a contract line when the lookup is used.

    With a little bit of modification, it will get the GP field down to the quote product form.

    Getting it to the quote level could be done with a workflow, more jscript or a plugin. I'm thinking a plugin will be the best solution.

    Leon Tribe
    Want to hear me talk about all things CRM? Check out my blog
    http://leontribe.blogspot.com/
    or hear me tweet @leontribe

    // Get the lookup for the productid attribute on the contract line form.
    lookupItem = crmForm.all.productid.DataValue;
    
    
    
    //if (lookupItem[0] != null)
    if (lookupItem != null)
    {
        // Display the GUID of the lookup.
    //    alert(lookupItem[0].id);
    var productid = lookupItem[0].id;
    
    // Prepare variables for a product to retrieve.
    var authenticationHeader = GenerateAuthenticationHeader();
    
    // Prepare the SOAP message.
    var xml = "<?xml version='1.0' encoding='utf-8'?>"+ 
    "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"+
    " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+
    " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"+ 
    authenticationHeader+ 
    "<soap:Body>"+ 
    "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+ 
    "<entityName>product</entityName>"+ 
    "<id>"+productid+"</id>"+ 
    "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>"+ 
    "<q1:Attributes>"+ 
    "<q1:Attribute>new_supportvalue</q1:Attribute>"+ 
    "</q1:Attributes>"+ 
    "</columnSet>"+ 
    "</Retrieve>"+ 
    "</soap:Body>"+ 
    "</soap:Envelope>";
    // Prepare the xmlHttpObject and send the request.
    var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
    xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
    xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xHReq.setRequestHeader("Content-Length", xml.length);
    xHReq.send(xml);
    // Capture the result.
    
    
    var resultXml = xHReq.responseXML;
    
    // Check for errors.
    
    var errorCount = resultXml.selectNodes('//error').length;
    
    if (errorCount != 0)
    {
     var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
    
    alert(msg);
    }
    // Display the retrieved value.
    else
    {
    
    if (resultXml.selectSingleNode("//q1:new_supportvalue") != null)
    {
    
    var supportvaluenode = resultXml.selectSingleNode("//q1:new_supportvalue");
    
    var parsedsv = parseFloat(supportvaluenode.nodeTypedValue);
    
    crmForm.all.price.DataValue = parsedsv;
    
    }
    
    else
    {
    crmForm.all.price.DataValue = null;
    
    }
    
    }
    
    
    }
    else
    {
    crmForm.all.price.DataValue = null;
    
    }


    Want to hear me talk about all things CRM? Check out my blog http://leontribe.blogspot.com/ or hear me tweet @leontribe
    Sunday, August 9, 2009 10:20 AM