Skip to content

MobileCRM.UI.EntityForm.DetailCollection.addProductWithQuantity

rescocrm edited this page May 15, 2023 · 1 revision

[v10.0] Appends the product into sales order collection.

Resulting MobileCRM.DynamicEntity object implements method "update" which can be used to update the entity properties in the sales detail collection.

Arguments

Argument Type Description
product MobileCRM.Reference A reference of the product to be appended.
quantity Number Product quantity.
callback function(MobileCRM.DynamicEntity) The callback function which is called asynchronously with MobileCRM.DynamicEntity object as an argument.
errorCallback function(errorMsg) The errorCallback which is called in case of error.
scope Object The scope for callbacks.

This example demonstrates how to add a new product with quantity 2 into order detail.

function addNewProduct() {
	var product = new MobileCRM.FetchXml.Entity("product");
	product.addAttributes();
	var fetch = new MobileCRM.FetchXml.Fetch(product, 1); // only one product will be fetched.
	fetch.execute("DynamicEntities", function (res) {
		var productReference = new MobileCRM.Reference(res[0].entityName, res[0].id, res[0].primaryName);
		// add product to detail collection.
		MobileCRM.UI.EntityForm.DetailCollection.addProductWithQuantity(productReference, 2, function (orderDetail) {
			/// <param name="orderDetail" type="MobileCRM.DynamicEntity"/>
			// in success callback of function.
			// order detail will be updated automatically.
			// display info about current order detail
			MobileCRM.bridge.alert(JSON.stringify(orderDetail));
		}, MobileCRM.bridge.alert // Alert an error (if any)
		);
	}, MobileCRM.bridge.alert, null);
}
Clone this wiki locally