{"id":18899,"date":"2019-06-07T11:42:02","date_gmt":"2019-06-07T11:42:02","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=18899"},"modified":"2020-05-27T11:07:37","modified_gmt":"2020-05-27T11:07:37","slug":"execute-action-with-columnsetcomplextype-type-parameter-using-xrm-webapi-online-execute-in-dynamics-365-crm-v9-0","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2019\/06\/execute-action-with-columnsetcomplextype-type-parameter-using-xrm-webapi-online-execute-in-dynamics-365-crm-v9-0\/","title":{"rendered":"Execute Action with ColumnSet(ComplexType) type parameter Using Xrm.WebApi.online.execute in Dynamics 365 CRM V9.0"},"content":{"rendered":"<h2><strong>Introduction<\/strong><\/h2>\n<p style=\"text-align: justify;\">Microsoft has introduced\u00a0<strong>Xrm.WebApi.online.execute<\/strong>\u00a0to execute an action in Dynamics CRM version 9.0. In our last blog we have seen how to <a href=\"https:\/\/www.inogic.com\/blog\/2019\/01\/execute-action-using-xrm-webapi-online-execute-in-dynamics-365-crm-v9-0\/\" target=\"_blank\" rel=\"noopener noreferrer\">Execute action using Xrm.WebApi.online.execute in Dynamics CRM<\/a>. In this blog we will see how to execute action with \u201c<a href=\"https:\/\/docs.microsoft.com\/en-us\/dynamics365\/customer-engagement\/web-api\/columnset?view=dynamics-ce-odata-9\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>ColumnSet<\/strong><\/a><strong>(ComplexType)<\/strong>\u201d type property.<\/p>\n<p style=\"text-align: justify;\">Here we are executing \u201c<strong>GenerateQuoteFromOpportunity<\/strong>\u201d action for sample purpose as this action contains the \u201c<a href=\"https:\/\/docs.microsoft.com\/en-us\/dynamics365\/customer-engagement\/web-api\/columnset?view=dynamics-ce-odata-9\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>ColumnSet<\/strong><\/a><strong>(ComplexType)<\/strong>\u201d type parameter.<\/p>\n<p><strong>Properties of <a href=\"https:\/\/docs.microsoft.com\/en-us\/dynamics365\/customer-engagement\/web-api\/columnset?view=dynamics-ce-odata-9\" target=\"_blank\" rel=\"noopener noreferrer\">ColumnSet<\/a>(ComplexType) parameter:<\/strong><\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-18900\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/06\/xrm.jpg\" alt=\"xrm\" width=\"759\" height=\"181\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/06\/xrm.jpg 759w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/06\/xrm-300x72.jpg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/06\/xrm-660x157.jpg 660w\" sizes=\"(max-width: 759px) 100vw, 759px\" \/><\/p>\n<p>For these properties we need to add another getMetadata method as shown in the below example.<\/p>\n<p><strong>Syntax: <\/strong><\/p>\n<p>Xrm.WebApi.online.execute(request).then(successCallback, errorCallback);<\/p>\n<p><strong>successCallback:<\/strong> This function call is for when is action executed successfully.<\/p>\n<p style=\"text-align: justify;\"><strong>errorCallback:<\/strong> This function call is for when there is any error while executing action. It returns an error as result in string format.<\/p>\n<p style=\"text-align: justify;\">Given below is the example of how to write the function to execute \u201c<strong>GenerateQuoteFromOpportunity<\/strong>\u201d action:<\/p>\n<p><strong><u>Generate Parameters:<\/u><\/strong><\/p>\n<p>\/**<\/p>\n<p>* This function generates quote from opportunity using GenerateQuoteFromOpportunity action<\/p>\n<p>* @param formContext<\/p>\n<p>* @param opportunityID<\/p>\n<p>*\/<\/p>\n<p>function executeAction(executionContext) {<\/p>\n<p>let functionName = &#8220;executeAction&#8221;;<\/p>\n<p>var opportunityID = null;<\/p>\n<p>var formContext = null;<\/p>\n<p>try {<\/p>\n<p>debugger;<\/p>\n<p>\/\/Get form context<\/p>\n<p>formContext = executionContext.getFormContext();<\/p>\n<p>\/\/Get opportunity id<\/p>\n<p>opportunityID = !isValid(executionContext.getFormContext().data)<\/p>\n<p>|| !isValid(executionContext.getFormContext().data.entity)<\/p>\n<p>|| !isValid(executionContext.getFormContext().data.entity.getId)<\/p>\n<p>? null : executionContext.getFormContext().data.entity.getId();<\/p>\n<p>\/\/Set parameters<\/p>\n<p>var GenerateQuoteFromOpportunityReq = function (OpportunityId, ColumnSetVal) {<\/p>\n<p>this.OpportunityId = { &#8220;guid&#8221;: OpportunityId };<\/p>\n<p>this.ColumnSet = {<\/p>\n<p>&#8220;AllColumns&#8221;: ColumnSetVal,<\/p>\n<p>&#8220;getMetadata&#8221;: function () {<\/p>\n<p>return {<\/p>\n<p>boundParameter: null,<\/p>\n<p>operationType: 0,<\/p>\n<p>operationName: &#8220;GenerateQuoteFromOpportunity&#8221;,<\/p>\n<p>parameterTypes: {<\/p>\n<p>&#8220;AllColumns&#8221;: {<\/p>\n<p>&#8220;typeName&#8221;: &#8220;Edm.Boolean&#8221;, \/\/Primitive Type<\/p>\n<p>&#8220;structuralProperty&#8221;: 1<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>};<\/p>\n<p>this.getMetadata = function () {<\/p>\n<p>return {<\/p>\n<p>boundParameter: null,<\/p>\n<p>parameterTypes: {<\/p>\n<p>&#8220;OpportunityId&#8221;: {<\/p>\n<p>&#8220;typeName&#8221;: &#8220;Edm.Guid&#8221;, \/\/Primitive Type<\/p>\n<p>&#8220;structuralProperty&#8221;: 1<\/p>\n<p>},<\/p>\n<p>&#8220;ColumnSet&#8221;: {<\/p>\n<p>&#8220;typeName&#8221;: &#8220;mscrm.ColumnSet&#8221;, \/\/Complex Type<\/p>\n<p>&#8220;structuralProperty&#8221;: 2<\/p>\n<p>}<\/p>\n<p>},<\/p>\n<p>operationType: 0,<\/p>\n<p>operationName: &#8220;GenerateQuoteFromOpportunity&#8221;<\/p>\n<p>};<\/p>\n<p>};<\/p>\n<p>};<\/p>\n<p>var generateQuoteFromOpportunityReq = new GenerateQuoteFromOpportunityReq(opportunityID, true);<\/p>\n<p>}<\/p>\n<p><strong><u>Execute Action:<\/u><\/strong><\/p>\n<p>Xrm.WebApi.online.execute(generateQuoteFromOpportunityReq).then(function (result) {<\/p>\n<p>\/\/Validate result<\/p>\n<p>if (!isValid(result) || !isValid(result[&#8220;responseText&#8221;])) {<\/p>\n<p>return;<\/p>\n<p>}<\/p>\n<p>else {<\/p>\n<p>\/\/get result in JSON object<\/p>\n<p>var resultJson = JSON.parse(result[&#8220;responseText&#8221;]);<\/p>\n<p>\/\/Validate JSON<\/p>\n<p>if (isValid(resultJson)) {<\/p>\n<p>\/\/Validating the attributes<\/p>\n<p>if (!isValid(Xrm) || !isValid(Xrm.Navigation)) { return; }<\/p>\n<p>\/\/openAlertDialog<\/p>\n<p>Xrm.Navigation.openAlertDialog({ confirmButtonLabel: &#8220;Ok&#8221;, text: &#8220;Quote with ID: &#8221; + resultJson.quoteid + &#8221; is generated successfully. &#8221; });<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}, function (error) {<\/p>\n<p>throwError(functionName, error);<\/p>\n<p>});<\/p>\n<p>} catch (error) {<\/p>\n<p>throwError(functionName, error);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>On success it returns a promise object with specific attributes.<\/p>\n<p style=\"text-align: justify;\">In above example we have used \u2018AllColums\u2019 property of \u201c<a href=\"https:\/\/docs.microsoft.com\/en-us\/dynamics365\/customer-engagement\/web-api\/columnset?view=dynamics-ce-odata-9\"><strong>ColumnSet<\/strong><\/a><strong>(ComplexType)<\/strong>\u201d parameter. In the same way we can use \u2018Columns\u2019 parameter. We just need to set \u201c<strong>Edm.String<\/strong>\u201d as <strong>typename<\/strong> in <strong>getMetadata <\/strong>method.<\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p style=\"text-align: justify;\">In this blog, we have seen how we can execute action with \u201c<a href=\"https:\/\/docs.microsoft.com\/en-us\/dynamics365\/customer-engagement\/web-api\/columnset?view=dynamics-ce-odata-9\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>ColumnSet<\/strong><\/a><strong>(ComplexType)<\/strong>\u201d type parameter using Xrm.WebApi.online.execute in Dynamics 365 CRM V9.0.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/product\/productivity-pack\/click-2-clone-microsoft-dynamics-crm-records\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-18901\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/06\/Click2Clone-One-Click-Productivity-App-to-Copy_clone-Dynamics-365_CRM-Records.png\" alt=\"Click2Clone-One-Click-Productivity-App-to-Copy_clone-Dynamics-365_CRM-Records\" width=\"800\" height=\"200\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/06\/Click2Clone-One-Click-Productivity-App-to-Copy_clone-Dynamics-365_CRM-Records.png 800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/06\/Click2Clone-One-Click-Productivity-App-to-Copy_clone-Dynamics-365_CRM-Records-300x75.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/06\/Click2Clone-One-Click-Productivity-App-to-Copy_clone-Dynamics-365_CRM-Records-768x192.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/06\/Click2Clone-One-Click-Productivity-App-to-Copy_clone-Dynamics-365_CRM-Records-660x165.png 660w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Microsoft has introduced\u00a0Xrm.WebApi.online.execute\u00a0to execute an action in Dynamics CRM version 9.0. In our last blog we have seen how to Execute action using Xrm.WebApi.online.execute in Dynamics CRM. In this blog we will see how to execute action with \u201cColumnSet(ComplexType)\u201d type property. Here we are executing \u201cGenerateQuoteFromOpportunity\u201d action for sample purpose as this action contains\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2019\/06\/execute-action-with-columnsetcomplextype-type-parameter-using-xrm-webapi-online-execute-in-dynamics-365-crm-v9-0\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":23725,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[65],"tags":[1813],"class_list":["post-18899","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-webapi","tag-web-api"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/18899","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=18899"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/18899\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/23725"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=18899"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=18899"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=18899"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}