locked
CRM 2013 opportunity product set price from javascript RRS feed

  • Question

  • Hi, I have a problem when trying to change price per unit programmatically on opportunity product form. It seems to work but after the form is saved the price change back to default.

    I've tried to use this code to fix the problem:

    Xrm.Page.getAttribute('ispriceoverridden').setValue(true);
    Xrm.Page.getAttribute('priceperunit').setValue(price);
    Xrm.Page.getAttribute('ispriceoverridden').setSubmitMode('always');
    Xrm.Page.getAttribute('priceperunit').setSubmitMode('always');
    Xrm.Page.data.entity.save();

    This forcing new values to be saved but also throws sql errors:

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Generic SQL error.Detail:
    <OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
      <ErrorCode>-2147204784</ErrorCode>
      <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
      <Message>Generic SQL error.</Message>
      <Timestamp>2014-05-19T12:45:22.7328548Z</Timestamp>
      <InnerFault i:nil="true" />
      <TraceText i:nil="true" />
    </OrganizationServiceFault>

    Monday, May 19, 2014 1:06 PM