{"id":648,"date":"2020-07-22T12:45:47","date_gmt":"2020-07-22T12:45:47","guid":{"rendered":"http:\/\/morecpq.com\/?p=648"},"modified":"2024-02-08T09:43:38","modified_gmt":"2024-02-08T14:43:38","slug":"cpq-qle-qcp-update-group-values","status":"publish","type":"post","link":"https:\/\/morecpq.com\/index.php\/2020\/07\/22\/cpq-qle-qcp-update-group-values\/","title":{"rendered":"CPQ &#8211; QLE &#8211; QCP &#8211; Update Group Values!"},"content":{"rendered":"\n<p>If you&#8217;re here you&#8217;re eagerly trying to figure out how to update Quote Line Group values in a price rule.  Unfortunately, you can&#8217;t.  Yet.  But you can in a QCP!  Here&#8217;s a basic sample that copies the Quote Account value into the Quote Line Group Account field. <\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>QCP Rules<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Methods have to be &#8220;export function &#8230;&#8221;.  You can&#8217;t just declare a function and expect it to work properly.<\/li>\n\n\n\n<li>You must implement one of the <a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.222.0.cpq_dev_plugins.meta\/cpq_dev_plugins\/cpq_dev_jsqcp_methods.htm\">expected functions<\/a> (onInit, onBeforeCalculate, onBeforePriceRules, onAfterPriceRules, onAfterCalculate, isFieldVisible, isFieldEditable).<\/li>\n\n\n\n<li>You must keep your &#8220;fields&#8221; fields on the Custom Script record up to date with the fields you&#8217;re referencing\/updating within the QCP.  If you&#8217;re touching line fields, add those fields to the Quote Line Fields field.  If you&#8217;re touching group fields, add those fields to the Quote Line Group Fields field.<\/li>\n<\/ol>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Expected Function Headers<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ ---------------------------------------------------------\n\/\/ these functions expect a Promise.resolve(); at the end.\n\/\/ ---------------------------------------------------------\nexport function onInit(lines) { Promise.resolve(); }\nexport function onBeforeCalculate(quote, lines) { Promise.resolve(); }\nexport function onBeforePriceRules(quote, lines) { Promise.resolve(); }\nexport function onAfterPriceRules(quote, lines) { Promise.resolve(); }\nexport function onAfterCalculate(quote, lines) { Promise.resolve(); }\n\n\/\/ ---------------------------------------------------------\n\/\/ these functions expect a boolean at the end.\n\/\/ ---------------------------------------------------------\nexport function isFieldVisible(fieldName, lineRecord) { return true; }\nexport function isFieldEditable(fieldName, lineRecord) { return true; }<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Example After Calculate Function<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/QuoteCalculatorJS\nexport function onAfterCalculate(quote, lines) {\n    if (quote.groups &amp;&amp; quote.groups.length > 0) {\n        quote.groups.forEach(function(group) {\n            if (group.record != null) {\n                group.record&#91;'SBQQ__Account__c'] = quote.record&#91;'SBQQ__Account__c'];\n\n                var groupListTotal = 0;\n                \/\/ if there are lines,\n\u00a0\u00a0\u00a0\u00a0            if (lines &amp;&amp; lines.length > 0) {\n                    \/\/ loop through lines.\n        \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0    lines.forEach(function(line) {\n                        \/\/ if this line's group id equals this group's id,\n                        if (group.record&#91;'Id'] == line.record&#91;'SBQQ__Group__c']) {\n                            groupListTotal += line.record&#91;'SBQQ__ListPrice__c'];\n                        }\n                    });\n                }\n\n                group.record&#91;'ListTotal__c'] = groupListTotal;\n            }\n        });\n    }\n\n    return Promise.resolve();\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re here you&#8217;re eagerly trying to figure out how to update Quote Line Group values in a price rule. Unfortunately, you can&#8217;t. Yet. But you can in a QCP! Here&#8217;s a basic sample that copies the Quote Account value into the Quote Line Group Account field. QCP Rules Expected Function Headers Example After Calculate &hellip;<br \/><a href=\"https:\/\/morecpq.com\/index.php\/2020\/07\/22\/cpq-qle-qcp-update-group-values\/\" class=\"more-link pen_button pen_element_default pen_icon_arrow_double\">Continue reading <span class=\"screen-reader-text\">CPQ &#8211; QLE &#8211; QCP &#8211; Update Group Values!<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-648","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/posts\/648","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/comments?post=648"}],"version-history":[{"count":18,"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/posts\/648\/revisions"}],"predecessor-version":[{"id":2725,"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/posts\/648\/revisions\/2725"}],"wp:attachment":[{"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/media?parent=648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/categories?post=648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/tags?post=648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}