locked
Create Contract line Example RRS feed

  • Question

  • Im trying to create a custom workflow that creates a contract line, however it isnt working and i am unable to see a error in a trace!

    does anyone have any examples of the Create Code for a contract line (detail)

    Thanks

    Jonathan


    Jonathan Nachman MBSP, MCTS

    Microsoft CRM Technical Blog

    Technical CRM Consultant for KMS Software
    Saturday, May 29, 2010 5:47 PM

Answers

  • Hi

    To create a contract detail (contract line), create an instance of the contractdetail class and provide the values for the properties you want to create. The instance specified must contain all the attributes that are marked as system required. If the entity instance includes attributes that are not valid for create, they will be ignored.

    You can  see  an  example  of here.

    http://software.itags.org/crm/130226/


    Muhammad Ali Khan
    http://malikhan.wordpress.com
    Saturday, May 29, 2010 6:19 PM

All replies

  • Hi

    To create a contract detail (contract line), create an instance of the contractdetail class and provide the values for the properties you want to create. The instance specified must contain all the attributes that are marked as system required. If the entity instance includes attributes that are not valid for create, they will be ignored.

    You can  see  an  example  of here.

    http://software.itags.org/crm/130226/


    Muhammad Ali Khan
    http://malikhan.wordpress.com
    Saturday, May 29, 2010 6:19 PM
  • The answer wasnt complete.... however i moved the try and catch around and finally found he error.....

     

    thank you though...

     

    Jonathan


    Jonathan Nachman MBSP, MCTS

    Microsoft CRM Technical Blog

    Technical CRM Consultant for KMS Software
    Monday, May 31, 2010 10:50 AM
  • following example code for the same..

    try
    {
    contractdetail myCrmObject = new contractdetail();
    
    
    // fill address id from contract (myContract is contract)
    myCrmObject.serviceaddress = CrmTypes.CreateLookup(EntityName.customeraddress.ToString(), myContract.serviceaddress.Value);
    
            // fill contract id      
    myCrmObject.contractid = CrmTypes.CreateLookup(EntityName.contract.ToString(), myContract.contractid.Value);
    
    // myProduct is product for this contract
    myCrmObject.productid = CrmTypes.CreateLookup(EntityName.product.ToString(), myProduct.productid.Value);
    myCrmObject.title = myProduct.name;
                
    
    myCrmObject.uomid = CrmTypes.CreateLookup(EntityName.uom.ToString(), myProduct.uomid.Value);
              
    
     if (myContract.customerid.type.Equals(EntityName.account.ToString()))
    {
    myCrmObject.customerid = CrmTypes.CreateCustomer(EntityName.account.ToString(), myContract.customerid.Value);
    }
    else if (myContract.customerid.type.Equals(EntityName.contact.ToString()))
    {
    myCrmObject.customerid = CrmTypes.CreateCustomer(EntityName.contact.ToString(), myContract.customerid.Value);
    }
    
    //default this to 999
    myCrmObject.totalallotments = CrmTypes.CreateCrmNumber(999);
    
    myCrmObject.net = CrmTypes.CreateCrmMoney(1);
              
    myCrmObject.price = CrmTypes.CreateCrmMoney(1);
    myCrmObject.discount = CrmTypes.CreateCrmMoney(1);
             
    myCrmObject.initialquantity = CrmTypes.CreateCrmNumber(1);
    
    // Contract Line Dates
    DateTime theStartDate = DateTime.Parse(myContract.activeon.Value.ToString());
    string strStartDate = theStartDate.ToString("s");
    myCrmObject.activeon = CrmTypes.CreateCrmDateTime(strStartDate);
    
    
    DateTime theEndDate = DateTime.Parse(myContract.expireson.Value.ToString());
    string strEndDate = theEndDate.ToString("s");
    myCrmObject.expireson = CrmTypes.CreateCrmDateTime(strEndDate);
    
    myService.Create(myCrmObject);
    }
    catch (SoapException ex)
    {        
    throw (ex);
    }
    catch (Exception ex)
    {
    throw (ex);
    }
    Monday, May 31, 2010 11:59 AM