Friday, 22 December 2017

vlocity - omniscript formula to get firstday of current month


Add the below in the formula box to get first day of current month

DATE(
IF(
OR(%Month%==null,%Year%==null),
 MONTH(TODAY())+'/02/'+YEAR(TODAY()),
(%Month%+'/'+'02'+'/'+%Year%)
)
)


Tuesday, 5 December 2017

salesforce - trigger before update



Trigger Code:
==========

trigger UpdateClosedCaseTrigger on Case (before update) {
//before update 
    if(Trigger.isUpdate && Trigger.isBefore){
        UpdateClosedCase_Helper.updateCase(Trigger.new,Trigger.oldMap,Trigger.newMap);
    }
}


Helper Code:
==========

public class UpdateClosedCaseHelper {
    public static boolean skipSuperUserFilter = false;
    public static void updateCase(List<Case> newcaselist,Map<Id,Case> oldMap,Map<Id,Case> newMap){
        if(!skipSuperUserFilter){
            //get current user info
            User u=[SELECT Id,Support_Super_User__c From User WHERE Id=:UserInfo.getUserId()];
            Set<Id> caseIdset=new Set<Id>();
            Map<Id,case> junctionMap=new Map<Id,case>();
            //get all case id's
            for(Case cd:newcaselist){
                caseIdset.add(cd.Id);
                junctionMap.put(cd.Id,cd);
            }
            //query all child cases          
            for(Case c:[SELECT Id, status,(select Id,status from cases) FROM Case WHERE Id IN:caseIdset]){
                //check for value change
                if(oldMap.get(c.Id)!=newMap.get(c.Id)){
                    //case is not going to close
                    if(!newMap.get(c.Id).status.equals('Closed') &&
                      !newMap.get(c.Id).status.equals('Resolved')){
                        if(u.Support_Super_User__c){
                            //update case
                        }
                        else{
                            if(oldMap.get(c.Id).status.equals('Closed'))
                                c.addError('Please contact your Almac Super User to re-open closed cases');
                            else{
                                //update case
                            }
                        }                     
                    }else{
                        //closing or resolving case
                        if((newMap.get(c.Id).status.equals('Closed') || newMap.get(c.Id).status.equals('Resolved')) &&
                           !isAllchildsClosed(c.cases)){                     
                               if(u.Support_Super_User__c){
                                   //update case
                               }
                               else{
                                   if(oldMap.get(c.Id).status.equals('Closed'))
                                       c.addError('Please contact your Almac Super User to re-open closed cases');
                                   else{
                                       //update case
                                   }
                               }
                           }
                        else{
                            junctionMap.get(c.Id).addError('Please close all child cases before Closing/Resolving it');
                        }
                    }
                }
            } 
        }
    }
    public static boolean isAllchildsClosed(List<Case> childs){
        boolean flag=false;
        for(Case c:childs){
            if(!'Closed'.equals(c.Status)){
                flag=true;
                break;
            }
        }
        return flag;
    }
}



Notes:
=====
1.Records will be updated only if Trigger.new list is iterated in helper class. in below case the helper class must contain the below statements, no explicity update statement needed.

for(Case c:newcaselist){
      c.status='Closed';
}


2.Related fields like owner.name, account.name are not available in newcaselist, we need to query them in helper class and all other object fields are available to update in helper class.


 

slds - ui:inputPhone validation



Component.cmp
============

<ui:inputPhone aura:id="phonenumber" class="slds-input" value="{!v.groupAccount.phoneNumber}" placeholder=" " change="{!c.onEnterPhone}" />




Controller.js
=========
 onEnterPhone : function(component, event, helper) {
        try{
        console.log('PortalGroupNew Controller onEnterPhone');
         var inputCmp = component.find("phonenumber");
        var value = inputCmp.get("v.value");
        while(value.includes('+'))
value=value.replace('+','');
        while(value.includes('-'))
        value=value.replace('-','');
        while(value.includes('('))
        value=value.replace('(','');
        while(value.includes(')'))
        value=value.replace(')','');
        // is input numeric?
        if (isNaN(value)) {
            inputCmp.set("v.errors", [{message:"Input not a number: " + value}]);
        } else {
            inputCmp.set("v.errors", null);
        }
        }catch(err){
            console.log('phone validation:'+err.stack);
        }
    }

 

Monday, 4 December 2017

vlocity - onclick javascript button on omniscript dataraptor post action

HTML template Id:  sendEmail.html
element Id: OppUpdateEmailConga

give HTML template Id to the dataraptor post action html template section.


place the below code in omniscript configuration


CUSTOM HTML TEMPLATES:

<style>
.inputpremium{
display:none;
}
.via-slds ng-form.ng-valid span.vlc-asterix.icon-v-asterix:before{
color: #50e3c2
}
    .vlc-slds--tertiary-container{
    visibility:hidden;
    }
    div[comma-value]{
      position:relative;
      font-weight: 600;
    }
    div[comma-value]:before{
      content: attr(comma-value);
      position:absolute;
      left:0;
    }
    div[comma-value] input{
      color:#fff;
    }
    </style>
    <script>
        baseCtrl.prototype.$scope.$root.updatepremium = function() {
            updatecommify();
        }

        baseCtrl.prototype.$scope.$root.sendEmail= function() {
            sendEmail();
        }

</script>
<script type="text/ng-template" id="downloadstepoverride.html">
        <div class="slds-grid vlc-slds-step--container" vlc-slds-window-scroll="test">
 
 
            <section id='{{::child.name}}'
                    ng-show='child.bAccordionActive && child.bAccordionOpen'
                    class="step-step slds-size--1-of-1">
 
                <!-- banner template -->
                <vlc-slds-banner></vlc-slds-banner>
 
                <!-- article when embedded in omniscript -->
                <vlc-slds-embedded-article></vlc-slds-embedded-article>
 
                <form novalidate
                    role='form'
                    stepForm
                    name='{{::bpTree.sOmniScriptId}}-{{$index}}'
                    id='{{::bpTree.sOmniScriptId}}-{{$index}}'
                    vlc-slds-disable-auto-complete="testing"
                    class='slds-grid slds-wrap'>
 
                    <!-- child controls in the step new comment-->
                    <div class='slds-col--padded slds-size--1-of-1'>
                        <div  class="slds-grid slds-wrap slds-grid--pull-padded">
                            <child vlc-slds-change-inline-templates="::child.eleArray[0].propSetMap.showInputWidth"
                                class="slds-size--1-of-1 slds-medium--1-of-1 slds-large-size--{{child.eleArray[0].propSetMap.controlWidth}}-of-12"
                                ng-repeat='child in ::children = child.children'
                                ng-show='::!child.eleArray[0].propSetMap.hide'
                                ng-if='(child.eleArray[0].propSetMap.hide && child.eleArray[0].type!=="Formula")||(!child.eleArray[0].propSetMap.show || evaluateShow(child.eleArray[0], this))'>
                            </child>
                        </div>
                    </div>
 
                    <div class='slds-col--padded slds-size--1-of-1 slds-m-top--medium slds-m-bottom--medium'>
 
                        <div class='slds-grid slds-wrap vlc-slds-button--footer'>
 
                            <div class='vlc-slds--tertiary-container'>
 
                                <div class='vlc-slds-button--tertiary'
                                    ng-if='child.bAccordionActive'
                                    confirmed-click='cancel()'
                                    ng-confirm-click='{{::child.propSetMap.cancelMessage}}'>
                                    {{::child.propSetMap.cancelLabel}}
                                </div>
 
                                <!-- test -->
                                <div ng-show='!child.bHasNext'
                                    class='vlc-slds-button--tertiary'
                                    ng-if='bpTree.scriptState == "saveAndResume" && child.bAccordionActive'
                                    vlc-animation-slider="test"
                                    confirmed-click='completeScript(true)'
                                    ng-confirm-click='{{::child.propSetMap.completeMessage}}'>
                                    {{::child.propSetMap.completeLabel}}
                                </div>
 
 
                                <div class='vlc-slds-button--tertiary'
                                    ng-if='bpTree.propSetMap.allowSaveForLater && bpTree.scriptState !== "review" && child.bAccordionActive'
                                    confirmed-click='saveForLater(child)'
                                    ng-confirm-click='{{::child.propSetMap.saveMessage}}' >
                                    {{::child.propSetMap.saveLabel}}
                                </div>
 
                            </div>
 
                            <div class='slds-size--1-of-1 slds-medium-size--6-of-12'>
 
                                <div class='slds-grid slds-wrap slds-grid--pull-padded vlc-slds-small--size-column' style="justify-content:flex-end">
                     
                        <!-- OMNI:2008 -->
                        <div ng-if='child.bHasPrevious'
                        class='slds-size--1-of-1 slds-medium-size--{{::child.propSetMap.previousWidth}}-of-12 vlc-slds-remote-action--button'>
 
                        <div class="slds-form-element__control">
 
                            <div class="vlc-control-wrapper">
                         
                            <div
                                id="{{::child.name + '_prevBtn'}}"
                                class="slds-box vlc-slds-box--neutral"
                                ng-click='sidebarNav(bpTree.children[bpTree.response.lastStepNo])'
                                aria-hiddens="true"
                                vlc-animation-slider="test"
                                reverse="true">
 
                                <p>
                                {{::child.propSetMap.previousLabel}}
                                </p>
 
                            </div>
 
                            </div>
 
                        </div>
 
                        </div>
 
                                    <div ng-if='child.bHasNext'
                        class='slds-size--1-of-1 slds-medium-size--{{::child.propSetMap.nextWidth}}-of-12 vlc-slds-remote-action--button'>
 
                                        <div class="slds-form-element__control">
 
                                            <div class="vlc-control-wrapper">
 
                                                <div
                                id="{{::child.name + '_nextBtn'}}"
                                ng-click='nextRepeater(child.nextIndex, child.indexInParent)'
                                                    ng-disabled='checkValidity(this, child.index, child.indexInParent, "Step", null, true)'
                                                    vlc-animation-slider='test'
                                                    class='slds-box'>
                                                    <p>{{::child.propSetMap.nextLabel}}</p>
                                                </div>
 
                                            </div>
                                        </div>
 
                                    </div>
 
                                </div>
 
                            </div>
 
                        </div>
 
                    </div>
 
                </form>
            </section>
        </div>
</script>
<script type="text/ng-template" id="dandopremiumoverride.html">
        <div class="slds-col--padded slds-size--1-of-1">
            <ng-form name='loopform'
                     class='slds-form-element vlc-flex vlc-slds-text-block vlc-slds-rte'
                     id='{{::child.eleArray[0].name}}'>
     
                <label class='slds-form-element__label'>
                </label>
     
                <div class="slds-form-element__control">
                    <p>
                        <h5>
                            <strong>&nbsp;</strong>Premium:&nbsp; <strong>&nbsp; &nbsp;{{bpTree.response.QuickQuote.Block1|n.DNOPremium | currency:"USD$"}}&nbsp;</strong>
                        </h5>
                    </p>
                </div>
            </ng-form>
        </div>
</script>
<script type="text/ng-template" id="premiumcalculationoverride.html">
    <div class='slds-col--padded slds-size--1-of-1'>
 
        <ng-form name='loopform'
                 class='slds-form-element vlc-flex vlc-form-group vlc-slds-remote-action--button'
                 ng-repeat='control in child.eleArray'>
 
            <div class="slds-form-element__control">
 
                <div class="vlc-control-wrapper">
 
                    <div id='{{::control.name}}'
                         class='slds-box'
                         title='{{::control.propSetMap.label}}'
                         ng-click='buttonClick(this.bpTree.response, control, this);$root.updatepremium();'>
                        <p>{{::control.propSetMap.label}}</p>
                    </div>
 
                </div>
 
                <div class='vlc-sub-block'></div>
 
            </div>
 
        </ng-form>
 
    </div>
 
</script>
<script type="text/ng-template" id="quickquoteblockoverride.html">
    <div class="slds-col--padded slds-size--1-of-1">
     
            <ng-form name='loopform'
                     class='slds-form-element vlc-flex slds-clearfix vlc-slds-block'
                     id ='{{::control.name}}'
                     ng-repeat='control in child.eleArray' >
     
                <div class="slds-form-element__control">
     
                    <!-- add block label -->
                    <label vlc-slds-toggle="toggle"
                           class="slds-form-element__label slds-clearfix" ng-if="::control.propSetMap.label">
     
                        <slds-svg-icon aria-hidden="true"
                                       sprite="'utility'"
                                       icon="'chevrondown'"
                                       size="'small'"
                                       extra-classes="'vlc-slds-collapse slds-button__icon slds-button__icon--large'">
                        </slds-svg-icon>
     
                        <slds-svg-icon aria-hidden="true"
                                       sprite="'utility'"
                                       icon="'chevronup'"
                                       size="'small'"
                                       extra-classes="'vlc-slds-expand slds-button__icon slds-button__icon--large'">
                        </slds-svg-icon>
     
     
                        <div class="slds-form-element__label--toggleText">
                            {{::control.propSetMap.label}}
                            <span ng-if='!( $first && $last )'>{{control.index+1}}</span>
                        </div>
                     
                        <div class="vlc-slds-control-action__container" vlc-bubble-canceller="testing">
     
                            <span ng-if='::control.propSetMap.repeat'
                                  ng-click='baseCtrl.addItem(this, child, $index)'
                                  aria-hidden="true">
                                {{::customLabels.OmniAdd}}
                            </span>
     
                            <span ng-if='child.eleArray.length > 1'
                                  ng-click='removeDomElement(this, child, $index)'
                                  vlc-slds-remove-item="ng-form.vlc-slds-block"
                                  aria-hidden="true">
                                {{::customLabels.OmniDelete}}
                            </span>
     
                        </div>
     
                    </label>
     
                 
                    <!-- block withing the main grid  ng-hide hides hthe block by default-->
                    <div class='slds-size--1-of-1 ng-hide'
                         vlc-slds-toggle-elem='visible'>
     
                        <div class="vlc-slds-control-action__container" vlc-bubble-canceller="test" ng-if="::!control.propSetMap.label">
     
                            <span ng-if='::control.propSetMap.repeat'
                                  ng-click='baseCtrl.addItem(this, child, $index)'
                                  aria-hidden="true">
                                  Add Alternative
                            </span>
     
                            <span ng-if='child.eleArray.length > 1'
                                  ng-click='removeDomElement(this, child, $index)'
                                  vlc-slds-remove-item="ng-form.vlc-slds-block"
                                  aria-hidden="true">
                                {{::customLabels.OmniDelete}}
                            </span>
     
                        </div>
     
                        <div  class="slds-grid slds-wrap slds-grid--pull-padded">
                            <child vlc-slds-change-inline-templates="::child.eleArray[0].propSetMap.showInputWidth"
                                   class="slds-size--1-of-1 slds-medium--1-of-1 slds-large-size--{{child.eleArray[0].propSetMap.controlWidth}}-of-12"
                                   ng-repeat='child in ::children = control.children'
                                   ng-show='::!child.eleArray[0].propSetMap.hide'
                                   ng-if='(child.eleArray[0].propSetMap.hide && child.eleArray[0].type!=="Formula")||(!child.eleArray[0].propSetMap.show || evaluateShow(child.eleArray[0], this))'>
                            </child>
                        </div>
                    </div>
     
                </div>
     
            </ng-form>
     
        </div>     
</script>
<script type="text/ng-template" id="sendEmail.html">
<div class='slds-col--padded slds-size--1-of-1'>

    <ng-form name='loopform'
             class='slds-form-element vlc-flex vlc-form-group vlc-slds-remote-action--button'
             ng-repeat='control in child.eleArray'>

        <div class="slds-form-element__control">

            <div class="vlc-control-wrapper">

                <div id='OppUpdateEmailConga'
                     class='slds-box'
                     title='{{::control.propSetMap.label}}'
                     ng-click='buttonClick(this.bpTree.response, control, this);$root.sendEmail();'>
                    <p>{{::control.propSetMap.label}}</p>
                </div>

            </div>

            <div class='vlc-sub-block'></div>

        </div>

    </ng-form>


</div>  </script>





CUSTOM JAVASCRIPT:

function updatecommify(){
        setTimeout(updatecommifydelay, 1000);
    }
function updatecommifydelay(){
        var slides = document.getElementsByClassName("inputpremium");
        for (var i = 0; i < slides.length; i++) {
            commify(slides.item(i));
        }
    }
    function commify(target) {
        var value = target.value;
        var chars = value.split("").reverse();
        var withCommas = [];
        for (var i = 1; i <= chars.length; i++) {
            withCommas.push(chars[i - 1]);
            if (i % 3 == 0 && i != chars.length) {
                withCommas.push(",");
            }
        }
        var val = withCommas.reverse().join("");
        val = '$' + val;
        target.parentNode.setAttribute("comma-value", val)
    }
function sendEmail() {
//Custom logic here  //Access to Data JSON with baseCtrl.prototype.$scope.bpTree.response
alert('Quote has been sent');
 }