Method Community

 

Create Estimate via API - customer link?

Last post 06-13-2013 4:41 PM by gbisaga. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 06-13-2013 6:49 AM

    Create Estimate via API - customer link?

    Hi, I am trying to use the API to create QB Estimates from the project management system I wrote for my client. I want to link my new Estimate to an existing Customer record, but I can't figure out how to do it. The best solution I have so far is to fill in the Estimate.Customer field with the FullName from the Customer I want to link to the estimate, but that requires a user interaction in the MethodCRM UI to confirm that's really the customer record that's required. It seems like, if I use the API, I should be able to create objects such as Estimates with no user interaction.

    In general, is there some reference that tells information like this and which fields in the Estimate "table" are really views into another table (like Customer)? Thanks for your support.

    Gary

  • 06-13-2013 2:56 PM In reply to

    Re: Create Estimate via API - customer link?

    Hi gbisaga,

    Using MethodAPIFieldList or MethodAPIFieldListV2 will tell you the related tables for a field (if any). For example when I query for information from the estimate table...the information I recieve(note I'm only showing the part for the field customer) is

    <Record>       <SupportsAdd>true</SupportsAdd>       <SupportsEdit>true</SupportsEdit>       <IsRequired>true</IsRequired>       <FieldName>Customer</FieldName>       <MaxSize>209</MaxSize>       <DataType>DropDown</DataType>       <DropdownFromTable>Customer</DropdownFromTable>       <DropdownDisplayField>FullName</DropdownDisplayField>     </Record>

    As you can see it tells me the customer field is a dropdown field, from the customer table.

    A barebones example of adding a new estimate for a customer that already exists in your method account is below. In my databsse the customer and transaction date are required fields. (Note, example is in C#)

    string[ arrInsertFieldsArray = new string[ { "Customer", "TxnDate" };

     string[ arrInsertValueArray = new string[ { "Amy Smith", "13/jun/2013" };

    MethodAPI.Service _MethodAPI = new MethodAPI.Service();

     lblMethodAPIInsertV2.Text = _MethodAPI.MethodAPIInsertV2(CompanyAccount, Login, Password, "", "estimate", arrInsertFieldsArray, arrInsertValueArray);

    _MethodAPI.Dispose();

    Dave

     

     

     


  • 06-13-2013 3:24 PM In reply to

    Re: Create Estimate via API - customer link?

    Dave, thank you for your response. I am creating my Estimate records very much like that. The problem is, when you view the Estimate record in the MethodCRM UI, the only Estimate field that is filled in is the Customer field itself - "Amy Smith" in your example. All the other fields that were present in the Customer record - Billing Address, Shipping Address, etc. - are still blank until you manually go in through the UI and re-select the customer from the Customer pulldown.

    Is there any way through the API to make those other fields populate so that no user interaction with the UI is required? Thanks!

    Gary

  • 06-13-2013 3:52 PM In reply to

    Re: Create Estimate via API - customer link?

    Gary

    I'm not sure if this is your question but in order to get all the other info populated you would need an extra call.  The flow might look like this.

    1. Call Method to get the customer's record
    2. Parse customer record in name:value pairs
    3. Build up new estimate field and value arrays using customer info name:value pairs along with other estimate specific info 
    4. Call to Insert new estimate passing in the built up arrays.
    Mark Crews
    Cloud Consultancy
    Principal and Developer


    • 2012 MethodCRM Partner of the Year

    • 2012 MethodCRM Community Excellence Award

    • 2011 MethodCRM Community Excellence Award


    Visit our website to find out about our training, support, and customization services.
    website: cloudconsultancyllc.com
    blog: cloudconsultancyllc.com/blog/
    ph: 434.326.1601
    e: support@cloudconsultancyllc.com

    What is Method?
  • 06-13-2013 4:22 PM In reply to

    Re: Create Estimate via API - customer link?

    Answer


    Hi Gary,

    Just following up on Mark's point (he beat me to it)....you can query for information about any record in your method account using one of the following functions.: MethodAPISelect_DataSet , MethodAPISelect_DataSetV2, MethodAPISelect_XML, MethodAPISelect_XMLV2

    So continuing my example above, what if I wanted to include Amy Smith's BillAddressAddr1 and BillAddressAddr2 as part of my estimate? I can query for them something like the following

    MethodAPI.Service _MethodAPI = new MethodAPI.Service();

    lblMethodAPISelect_XMLV2.Text = _MethodAPI.MethodAPISelect_XMLV2(CompanyAccount, Login, Password, "", "customer", "BillAddressAddr1,BillAddressAddr2", "FullName = 'Amy Smith'", "", "", "");

    _MethodAPI.Dispose();

    The xml returned (which I've saved to a label in my example) would look something like(how you parse it out is your choice)

    <?xml version="1.0" encoding="windows-1252" ?><MethodAPI response = "Success" MaxRecords= "False"><MethodIntegration Table='customer'> <Record> <BillAddressAddr1>someaddy1</BillAddressAddr1> <BillAddressAddr2>someaddy2</BillAddressAddr2> </Record> </MethodIntegration></MethodAPI> 

     

    I could then update my insert to look like

    string[ arrInsertFieldsArray = new string[ { "Customer", "TxnDate", "BillAddressAddr1", "BillAddressAddr2" };  

    string[ arrInsertValueArray = new string[ { "Amy Smith", "13/jun/2013", "someaddy1", "someaddy2" };

    MethodAPI.Service _MethodAPI = new MethodAPI.Service();

     lblMethodAPIInsertV2.Text = _MethodAPI.MethodAPIInsertV2(CompanyAccount, Login, Password, "", "estimate", arrInsertFieldsArray, arrInsertValueArray);

     _MethodAPI.Dispose();

    So its just a matter of determining what you need in advance, pulling it from your account, then updating your insert to use the pulled information.

     

    Dave

     

  • 06-13-2013 4:24 PM In reply to

    Re: Create Estimate via API - customer link?

    Mark, thank you so much for your response. I think I was thinking of Method/QB as being more of a normalized relational database than it actually is. It sounds like all those Estimate fields like Billing and Shipping address are denormalized copies from Customers. That goes against my sensibilities of database design Smile but I understand that QB is an old database. Thanks, I will go back to it with this model in mind.

    Gary

  • 06-13-2013 4:41 PM In reply to

    Re: Create Estimate via API - customer link?

    Dave, thanks for your response also. Little by little things are sinking in. :-)

    Gary

Page 1 of 1 (7 items)