How to add multiple products in order through jquery RRS feed

  • Question

  • Hi,

    I am using html web resource.

    I want to create order and in which I  want to add multiple products using jquery.

    How can i achieve this?

    Monday, August 10, 2015 12:12 PM

All replies

  • Hello,

    Have you checked this article - https://msdn.microsoft.com/en-us/library/gg309549.aspx

    Dynamics CRM MVP
    My blog

    Monday, August 10, 2015 12:18 PM
  • Thanks for your reply,

    I checked this article but I want to add multiple products in single order ,but i cannot understand can i?

    Monday, August 10, 2015 12:23 PM
  • I will write pseudocode. I hope you will understand it.

    var orderDetails = [SalesOrderDetail1, SalesOrderDetail2, SalesOrdeDetail3];
    for(var i = 0; i < orderDetails.length; i++){

    Try to write something because it is really complicated for me to understand what exact issues do you have at the moment.

    Dynamics CRM MVP
    My blog

    Monday, August 10, 2015 12:33 PM
  • ohh..yes..! I am understanding little bit.

    I am describing  my full requirnment.please try to help

    My main goal is to generate Purchase order from sales order .

    so when user click on "Generate purchase order" i am giving him option  to select supplier and according to that I am creating Purchase order

    After user click create purchase order  i want to create purchase order .

    for example-this is my data..

    if user select this 2 suppliers then i have to create purchase order for 2 products-(i have to add 2 products in a signle purchase order).

    If user select 2 different suppliers theni have to create 2 purchase order

    Thank you

    • Edited by NikkiShah Monday, August 10, 2015 12:45 PM
    Monday, August 10, 2015 12:44 PM
  • Good to have context.

    Now I better understand your goal. Let's make another one step closer. Try to implement following:

    1. Create in your JS some kind of dictionary where you can store pair Supplier - SO(SalesOrder).

    2. Loop through lines doing following:

    2.1. Check if SO was already created for current supplier.

    2.2. If it was not - Create SalesOrder and put it to dictionary created in point 1.

    2.3. Create SalesOrderDetail for SalesOrder picked up on step 2.1 or created on step 2.2.

    That's pretty it.

    Dynamics CRM MVP
    My blog

    Monday, August 10, 2015 12:52 PM
  • thank you so much for your valuable reply

    I have one dought is that u have written so is it correct?.becasue i want to create purchase order

    Here I am writing my code..Is this correct?.and what change i have to made accourding to you for further move

      var supplier_data = []; 

         function generatepo() {

                $('#products tr').each(function () {
                    var supplier = $(this).find('.selectpicker').val();
                    if (supplier !== undefined) {
                        //get first td=product name
                        var pname1 = $(this).children(":first").text();
                        try {
                            var table = document.getElementById('products');
                            var rowCount = table.rows.length;                        
                            for (var r = 1, n = table.rows.length; r < n; r++) {
                                for (var c = 0, m = table.rows[r].cells.length - 1; c < m; c++) {                           
                                        key: table.rows[0].cells[c].innerHTML,
                                        value: table.rows[r].cells[c].innerHTML
                        } catch (e) {
                console.log = arrsupplier;

    Monday, August 10, 2015 1:19 PM
  • I'm really sorry but you will have to develop and troubleshoot your code with your own. I can only give you a direction where to look.

    Dynamics CRM MVP
    My blog

    Monday, August 10, 2015 1:23 PM
  • Ok..then i will come back to you after sometime.

    I want to ask one more thing

    I want to add supplier which is a look up field ..

    I am creating a record of purchase order and i want to add a value of a supplier(which is a look up field) how can i add?

    I tried it by supplier id and by supper name but i cant achieve success.

    Tuesday, August 11, 2015 9:32 AM
  • Work with lookups using OData should look like following:

    var PurchaseOrder = {
    CustomerId: {
    Id: "Guid of customer"
    ,LogicalName: "account"}

    Dynamics CRM MVP
    My blog

    Tuesday, August 11, 2015 9:43 AM
  • i have done like this..

    Supplier is a custom entity created by me as like below:

      CreateOneToManyRequest reqsupplier = new CreateOneToManyRequest()
                            Lookup = new LookupAttributeMetadata()
                                Description = new Label("The parent supplier of the Supplier entity", 1033),
                                DisplayName = new Label("Parent Supplier", 1033),
                                LogicalName = "new_parent_supplierid",
                                SchemaName = "new_parent_supplierid",
                                RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None)
                            OneToManyRelationship = new OneToManyRelationshipMetadata()
                                AssociatedMenuConfiguration = new AssociatedMenuConfiguration()
                                    Behavior = AssociatedMenuBehavior.UseCollectionName,
                                    Group = AssociatedMenuGroup.Details,
                                    Label = new Label("Supplier", 1033),
                                    Order = 10000
                                CascadeConfiguration = new CascadeConfiguration()
                                    Assign = CascadeType.Cascade,
                                    Delete = CascadeType.Cascade,
                                    Merge = CascadeType.Cascade,
                                    Reparent = CascadeType.Cascade,
                                    Share = CascadeType.Cascade,
                                    Unshare = CascadeType.Cascade
                                ReferencedEntity = _customEntityName,
                                ReferencedAttribute = "new_supplierid",
                                ReferencingEntity = _customEntityName,
                                SchemaName = "new_parent_supplier"

    and i have to add supplier  ..done like this.but not working

         test.new_parent_supplierid = {               
                        Id: Value(Id of a supplier),
                        LogicalName: "new_supplier"   

    • Edited by NikkiShah Tuesday, August 11, 2015 10:27 AM
    Tuesday, August 11, 2015 10:26 AM
  • Seems that you don't understand what you write.

    1. Provided code is obviously C# but you want to create record using "jQuery and JavaScript".

    2. You try to use metadata call to create a relationship between entities.

    3. You're trying to do complex operation and seems that you don't understand even basics (I'm really sorry but this seems to be the truth).

    After all what I would suggest is:

    1. Learn JavaScript basics - w3school is good enough for this.

    2. After you've completed point 1 - learn basics of CRM like work with fields, sections and tabs.

    3. After you've completed point 2 - learn how to develop code using OData/Rest calls.

    Dynamics CRM MVP
    My blog

    Tuesday, August 11, 2015 10:34 AM
  • I know that code is for c# .and i am using HTML web resource..

    I am just asking to you for understanding my question well..

    but no problem..thanks for advice.

    • Edited by NikkiShah Tuesday, August 11, 2015 10:49 AM
    Tuesday, August 11, 2015 10:43 AM