Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Custom command button to create Order Product record in Resco Mobile CRM

Posted on by Microsoft Employee

Hi,

We are using a custom entity for Inventory, which indicates the color and lot size for products and has many-to-one relation to Product entity.

Is there a way to create Order Product record in Resco Mobile CRM from a custom entity such as this one?
And the second question is how to create custom command button in Order form to use barcode scanner and create Order Product record by reading this custom entity values?

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Custom command button to create Order Product record in Resco Mobile CRM

    Thanks Thomas.

  • Verified answer
    Thomas David Dayman Profile Picture
    Thomas David Dayman 11,323 on at
    RE: Custom command button to create Order Product record in Resco Mobile CRM

    Solved this issue by using Offline HTML

    I created a Custom command on the Order form which triggered the java script below

    1. function storeBarCode(code) = Stores the barcode number
    2. function getEntityValues = Gets the salesorderid
    3. function fetchRecord = fetches the Inventory record where the barcode number equals the one we scanned before. It retrieves:
      1. Inventoryid
      2. productid
      3. Inventory name
    4. function createRecord(productId, quantity, inventoryId) = creates an order product connected with the parent order and populates it with the values retrieved from the other functions

    <!DOCTYPE html>
    
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <title>EntityList </title>
    	<meta http-equiv='X-UA-Compatible' content='IE=edge' />
    	<meta name='viewport' content='initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no'>
    	<script type='text/javascript' src='JSBridge.js'></script>
    </head>
    <body>
    	<script type="text/javascript">
    
    
    		var barcode;
    		var entityid;
    		var inventoryid;
    		var productid;
    		var inventoryname;
    		var quantity = 1;
    		
    		MobileCRM.UI.EntityForm.onCommand("custom_barcode",
    			function (entityForm) {
    				
    				var entity = entityForm.entity;								
    				MobileCRM.Platform.scanBarCode(
    				function (res) {
    					if (!res || res.length <= 0) {
    						sayError("No barcode");
    					}
    					else {
    						storeBarCode(res[0]);
    						barcode = res[0];
    						getEntityValues();
    					}
    				},
    				function (err) { sayError(err); }
    			);
    		},
    	true
    );
     
    function storeBarCode(code) {
    	MobileCRM.UI.EntityForm.requestObject(
    		function (entityForm) {
    			entityForm.entity.properties["productnumber"] = code;
    			entityid = entityForm.entity.properties["salesorderid"];
    		},
    		function (err) { sayError(err); }
    	);
    }
    
    
    function getEntityValues() {
    	MobileCRM.UI.EntityForm.requestObject(
    		function (entityForm) {
    			entityid = entityForm.entity.properties["salesorderid"];
    			fetchRecord();
    		},
    		function (err) { sayError(err); }
    	);
    }
    
    function fetchRecord() {
    	var entity = new MobileCRM.FetchXml.Entity("new_inventory");
    	entity.addAttribute("new_inventoryid");
    	entity.addAttribute("new_product");
    	entity.addAttribute("new_name");
    	
    	entity.filter = new MobileCRM.FetchXml.Filter();
        entity.filter.where("new_barcode", "eq", barcode);
    	
    	var fetch = new MobileCRM.FetchXml.Fetch(entity);
    		fetch.execute("Array",
    		function (result) {
    		for (var i in result)
    		{
    		var results = result[i]
    		    inventoryid = results[0];
    			productid = results[1].id;
    			inventoryname = results[2];
    
    			createRecord(productid, quantity, inventoryid);
    		}
    	},
    	function (error) {
    	alert("Error has occurred " + err);
    	},
    	null);
    
    	
    }
    
    function createRecord(productId, quantity, inventoryId) {
        //MobileCRM.bridge.alert("Barcode Number: " + barcode + " Sales Order Id: " + entityid + " FETCH Inventoryid: " + inventoryid + " FETCH productid: " + productid + " FETCH inventoryname " + inventoryname );
    	
    	var productRef = new MobileCRM.Reference("product", productId);
    	MobileCRM.UI.EntityForm.DetailCollection.add(
    		productRef,
    		function (orderDetail) {
    			/// <param name="orderDetail" type="MobileCRM.DynamicEntity"/>
    			orderDetail.properties['new_quantitybyseries'] = quantity;
    			orderDetail.properties["new_inventory"] = new MobileCRM.Reference("new_inventory", inventoryId, inventoryname);
    			
    			orderDetail.update(
    				function (err) {
    					if (err)
    						MobileCRM.bridge.alert(err);
    					else
    						MobileCRM.bridge.alert("Product added");
    				});
    		},
    		MobileCRM.bridge.alert
    	);
    }
    
    	</script>
    </body>
    </html>


  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Custom command button to create Order Product record in Resco Mobile CRM

    Hi Thomas,

    Thanks for your reply. We don't have trouble using the barcode type itself. Already we have that on Existing Product field in Order Product, or in other forms on any other fields.

    Also there's relation between order product and the custom entity.

    Here's our problem: as for the built-in process there's a "+" button on top of Order form (Products tab), which calls a lookup view of Products entity, and by selecting any product there (either by taping on it or using barcode scanner) an Order Product record will be created.

    We just want to replace that lookup view of Products with a lookup view of our custom entity, and create Order Product that way. (We want both Existing Product field and the custom one being populated as the result.)

  • Suggested answer
    Thomas David Dayman Profile Picture
    Thomas David Dayman 11,323 on at
    RE: Custom command button to create Order Product record in Resco Mobile CRM

    You can create Order Products in CRM Resco but you will need to give the user permission to create them. You will also need to add a relationship from order product to your custom entity.

    In woodford you can convert a simple text field to type of Barcode. Look here - crmgiant.eu/.../resco-mobile-crm-how-to

    You could also try using load reference to get the custom entity values. blog.resco.net/.../show-info-from-parent-on-a-child-form-e-g-see-the-relationship-type-of-the-account-whenever-you-open-up-a-contact

    Or you can just use JS/Offline html for all this. www.resco.net/javascript-bridge-reference

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans