Suggestions for displaying specific text after model Lookup compares ids

  • 1
  • Question
  • Updated 7 months ago
  • In Progress
  • (Edited)
Suggestions for displaying specific text after Model Lookup compares ids.  I have a contact model and campaign model. I select contacts and add them to campaign object.

Contact and campaign objects are on different tabs.  In order to avoid users from selecting duplicate contacts,  I would like to put in a comment that user already exists in campaign. 

I am using a ui only formula field which does a model look up to compare the ids.- MODEL_LOOKUP("CampaignMembers_Contact","Id","ContactId",{{Id}})

It returns the id of the contact.  But I would like to return a canned text " Contact alerady exists"  Anytime I try that the formula does not work.


Photo of Jaiti

Jaiti

  • 392 Points 250 badge 2x thumb

Posted 7 months ago

  • 1
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 12,054 Points 10k badge 2x thumb
Hi Jaiti,

Have you considered setting up an action that would remove the contact from the model once they've been selected? Not to *delete* them -- but you could use a row action that removes selected rows from model. That way the row can't be selected a second time. 

Or, you might also be able to set up a render or enable condition on the row or row action, which only enables/renders the row/row action if the selected contact's id # is NOT present in the campaign model. If that's not clear, let me know. 
Photo of Jaiti

Jaiti

  • 392 Points 250 badge 2x thumb
Hi Mark,
I tried both the suggestions not sure why they did not work:
1st

(Edited)
Photo of Jaiti

Jaiti

  • 392 Points 250 badge 2x thumb
Rendering condition also did not work :

Photo of Mike Dwyer

Mike Dwyer, Champion

  • 4,622 Points 4k badge 2x thumb
Jaiti, could you post the xml from the two models? I'd like to see what you are doing. Please include the entire nodes from <model> to </model>. Don't exclude anything even if it seems irrelevant.
Photo of Jaiti

Jaiti

  • 392 Points 250 badge 2x thumb
Thanks Mike. I was able to resolve this by adding this formula field "contactsincampaign" for which I used the formula - MODEL_LOOKUP("CampaignMembers_Contact","Id","ContactId",{{Id}}).  This added id on the "contactsincampaign" field where the contactid and id matched. 
Then Used a condition on the model to only display when the where the contactsincampaign" field was blank.

Photo of Jaiti

Jaiti

  • 392 Points 250 badge 2x thumb
Hi Mike, I feel I spoke to early but I have a new use case where I need a text field on the generic junction  - the account id in the campaign member model matched with the account id in junction object. 

Here is xml
<skuidpage showsidebar="false" showheader="true" tabtooverride="Campaigns" personalizationmode="server" theme="Workday Theme" cachepage="false">
    <resources>
        <labels/>
        <javascript>
            <jsitem location="inlinesnippet" name="CampaignMemberStatus" url="">var field = arguments[0],
    value = skuid.utils.decodeHTML(arguments[1]),
    $ = skuid.$,
    StatusModel,
    hasResponded = field.row.HasResponded || false,
    isMassUpdate = (typeof field.row.HasResponded === 'undefined');

// Find the CampaignMemberStatus model
$.each(skuid.model.list(),function(){
   if (this.objectName === 'CampaignMemberStatus') {
      StatusModel = this;
      return false;
   }
});

if (field.mode!=='edit'){
   skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);
} else {

   var entries = $.map(StatusModel.data,function(item){
       return {
            label: item.Label,
            value: item.Label,
            defaultValue: item.IsDefaultValue,
            isActive: true
       };
   });
    field.element.append(skuid.ui.renderers.PICKLIST.edit({
    value : value,
entries : entries,
renderas : field.options.type,
onChange : function(value) {
field.model.updateRow(field.row,field.id,value,{ initiatorId : field._GUID});
},
required : field.required,
addNoneOption: field.options.addNoneOption,
mode : field.mode,
buttonSetName : field.id + '_' + field._GUID,
noneLabel : field.options.noneLabel
}));
}</jsitem>
            <jsitem location="inlinesnippet" name="saveNewItemsInPopup" cachelocation="false" url="">var $ = skuid.$,
    params = arguments[0],
    component = params.component,
    popup = component.editor.element.closest('.ui-dialog-content'),
    modelsToSave = [],
    objLabelsToSave = [],
    uniqueModels = {};

popup.children().each(function(){
    var obj = $(this).data('object');
    if (obj &amp;&amp; obj.model &amp;&amp; !uniqueModels[obj.model.id]) {
        var model = obj.model;
        modelsToSave.push(model);
        if (model.data &amp;&amp; model.data.length) {
            if (model.data.length&gt;1) {
                objLabelsToSave.push(model.labelPlural);
            } else {
                objLabelsToSave.push(model.label);
            }
        }
        uniqueModels[obj.model.id] = 1;
    }
});

var message = 'Saving new ';
if (objLabelsToSave.length &lt; 3) {
    message += objLabelsToSave.join(' and ');
} else {
    var lastObj = objLabelsToSave.pop();
    message += objLabelsToSave.join(', ');
    message += ', and ' + lastObj;
}
message += '...';
popup.block({
    message: message
});

skuid.model.save(modelsToSave,{callback:function(result){
    if (result.totalsuccess){

        // Refresh the data in related Models on the page
        var uniqueRelatedObjectsToCheck = {},
            relatedModelsToUpdate = [];

        $.each(modelsToSave,function(){
            if (this.objectName &amp;&amp; !uniqueRelatedObjectsToCheck[this.objectName]) {
                uniqueRelatedObjectsToCheck[this.objectName] = 1;
            }
        });

        // Loop over all Models,
        // including the Models we've already saved,
        // and find ones that are on the same objects as the ones we've already saved.
        // Update them if they do not have unsaved changes.
        $.each(skuid.model.list(),function(){
            if (uniqueRelatedObjectsToCheck[this.objectName]
            &amp;&amp; !this.hasChanged) {
                relatedModelsToUpdate.push(this);
            }
        });
        
        $.when(skuid.model.updateData(relatedModelsToUpdate)).then(function(){
            $.each(popup.children(),function(){
                var obj = $(this).data('object');
                if (obj &amp;&amp; obj.unregister) obj.unregister();
            });
            popup.dialog('destroy');

            // Create new Rows in our Models to Save,
            // to prepare for the NEXT time someone creates a new record
            $.each(modelsToSave,function(){
                this.createRow();
            });

        });
    } else {
        popup.unblock();
    }
}});</jsitem>
            <jsitem location="inlinesnippet" name="AddMembers" cachelocation="false">var params = arguments[0],
   $ = skuid.$,
   objectName = params.model.objectName,
   items = params.item ? [params.item] : params.list.getSelectedItems(),
   MembersModel = skuid.model.getModel('CampaignMembers_'+objectName),
   StatusModel = skuid.model.getModel('DummyMemberStatus'),
   Status = StatusModel.getFieldValue(StatusModel.getFirstRow(),'Status',true);

var newRowIds = {};

$.each(items,function(i,item){
    var row = MembersModel.createRow({
        additionalConditions: [
            {
                field: objectName+'Id',
                value:item.row.Id
            },
            {
                field: 'Status',
                value: "Nominated"
            }
        ]    
   });
   MembersModel.updateRow(row,objectName,item.row);
   newRowIds[row.Id]=1;
});

// Refresh the fields in the Members model
// so that they will show the related field data, e.g. Lead.Email, Lead.Title
$.each(MembersModel.registeredLists,function(i,list){
   $.each(list.renderedItems,function(rowId,item){
      if (rowId in newRowIds) {
          item.refreshFields();
      } 
   });
});


   
</jsitem>
            <jsitem location="inlinecomponent" name="CampaignHierarchy" cachelocation="false" url="">var element = arguments[0],
   $ = skuid.$;

// Add our Parent Campaign into our Child Campaigns table,
// so that we have a single Model to interact with
var CCModel = skuid.model.getModel('ChildCampaigns');
var MainModel = skuid.model.getModel('Campaign');
var copyRow = $.extend({},MainModel.getFirstRow());
CCModel.adoptRow(copyRow,{doAppend:false});

//
// Html fragments
//

var mergeRowAsHtml = function(row,template){
  return CCModel.mergeRow(row,template).html();  
};
var mergeGlobalAsHtml = function(template){
  return skuid.utils.merge('global',template,{createFields:true,registerFields:false}).html();  
};

var numberCells = function(row){
    return '&lt;td&gt;' + mergeRowAsHtml(row,'{{NumberOfLeads}}') + '&lt;/td&gt;' + '&lt;td&gt;' + mergeRowAsHtml(row,'{{NumberOfContacts}}') + '&lt;/td&gt;' + '&lt;td&gt;' + mergeRowAsHtml(row,'{{NumberOfResponses}}') + '&lt;/td&gt;' + '&lt;td&gt;' + mergeRowAsHtml(row,'{{NumberOfConvertedLeads}}') + '&lt;/td&gt;' + '&lt;td&gt;' + mergeRowAsHtml(row,'{{AmountWonOpportunities}}') + '&lt;/td&gt;';
};    
    
var mainRowBody = function(row,indent) {
    return '&lt;tr class="nx-item"&gt;'
        // NAME cell
        + '&lt;td&gt;&lt;div class="nx-field ' + indent + '"&gt;&lt;div class="nx-field-text"&gt;'
        + mergeRowAsHtml(row,'{{Name}}')
        + '&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;'
        // NUMBER CELLS
        + numberCells(row)
        + '&lt;/tr&gt;';
};        

var template = 

    '&lt;table class="nx-skootable-data hierarchy-table"&gt;'

    //
    // BODY
    //
    + '&lt;tbody&gt;'

    //
    // Row for the PRIMARY CAMPAIGN
    //

    + '&lt;tr class="nx-item campaign-hierarchy-row1"&gt;'
    
    // NAME CELL
    + '&lt;td&gt;'
    + mergeRowAsHtml(CCModel.getFirstRow(),
        '&lt;div&gt;{{Name}}'
        // If we have a parent Campaign,
        // add a link to view that Parent
        + '{{#ParentId}}'
        + '&lt;div style="display:inline-block;"&gt; (&lt;a href="/{{{ParentId}}}"&gt;View Parent&lt;/a&gt;)&lt;/div&gt;'
        + '{{/ParentId}}'
        + ' '
        + '{{#Id}}'
        + '&lt;div style="display:inline-block;"&gt; (&lt;a href="/p/camp/ViewCampaignHierarchy/d?id={{{Id}}}"&gt;View Hierarchy&lt;/a&gt;)&lt;/div&gt;'
        + '{{/Id}}'
        + '&lt;/div&gt;'
    )
    
    + '&lt;/td&gt;'
    
    // NUMBERS CELLS
    + numberCells(CCModel.getFirstRow())
    
    + '&lt;/tr&gt;';

    //
    // Rows for the Child/Grand-child Campaigns
    //
$.each(CCModel.data,function(i,row){
    if (i===0)return true;// Skip the first row
    template += mainRowBody(row,"indent1");
    if (row.ChildCampaigns &amp;&amp; row.ChildCampaigns.records) {
        $.each(row.ChildCampaigns.records,function(i,cc){
           template += mainRowBody(cc,"indent2");
        });
    }
});

template += 
    '&lt;/tbody&gt;';
    
    // HEADER
    //
template += '&lt;thead&gt;'
    + '&lt;tr&gt;'
    + '{{#$Model.ChildCampaigns}}'
    + '&lt;th&gt;{{fieldsMap.Name.label}}&lt;/th&gt;'
    + '&lt;th&gt;{{fieldsMap.NumberOfLeads.label}}&lt;/th&gt;'
    + '&lt;th&gt;{{fieldsMap.NumberOfContacts.label}}&lt;/th&gt;'
    + '&lt;th&gt;{{fieldsMap.NumberOfResponses.label}}&lt;/th&gt;'
    + '&lt;th&gt;{{fieldsMap.NumberOfConvertedLeads.label}}&lt;/th&gt;'
    + '&lt;th&gt;{{fieldsMap.AmountWonOpportunities.label}}&lt;/th&gt;'
    + '{{/$Model.ChildCampaigns}}'
    + '&lt;/tr&gt;'
    + '&lt;/thead&gt;'

    //
    // TFOOT
    //
    + '&lt;tfoot&gt;'
    + '&lt;tr&gt;'
    + '&lt;th&gt;Hierarchy Total&lt;/th&gt;'
    + '&lt;th&gt;'+mergeRowAsHtml(CCModel.getFirstRow(),'{{HierarchyNumberOfLeads}}')+'&lt;/th&gt;'
    + '&lt;th&gt;'+mergeRowAsHtml(CCModel.getFirstRow(),'{{HierarchyNumberOfContacts}}')+'&lt;/th&gt;'
    + '&lt;th&gt;'+mergeRowAsHtml(CCModel.getFirstRow(),'{{HierarchyNumberOfResponses}}')+'&lt;/th&gt;'
    + '&lt;th&gt;'+mergeRowAsHtml(CCModel.getFirstRow(),'{{HierarchyNumberOfConvertedLeads}}')+'&lt;/th&gt;'
    + '&lt;th&gt;'+mergeRowAsHtml(CCModel.getFirstRow(),'{{HierarchyAmountWonOpportunities}}')+'&lt;/th&gt;'
    + '&lt;/tr&gt;'
    + '&lt;/tfoot&gt;';
    
template += '&lt;/table&gt;';

element.html(skuid.utils.merge('global',template,{createFields:true}).html());</jsitem>
        </javascript>
        <css>
            <cssitem location="inline" name="hierarchy table" cachelocation="false">.hierarchy-table .indent1 {
    padding-left: 3.0em;
}

.hierarchy-table .indent2 {
    padding-left: 6.0em;
}

.hierarchy-table tfoot {
    background-color: #f2e7d1;
}

.campaign-hierarchy-row1 .nx-field {
    display:inline-block;
}

.nx-skootable-data tbody .nx-item.campaign-hierarchy-row1 td {
    background-color: #fffcf3;
}</cssitem>
        </css>
        <actionsequences uniqueid="sk-To7-1431"/>
    </resources>
    <models>
        <model id="Campaign" limit="1" query="false" createrowifnonefound="false" orderby="" sobject="Campaign" datasource="salesforce" processonclient="false">
            <fields>
                <field id="Name"/>
                <field id="Type"/>
                <field id="Status"/>
                <field id="StartDate"/>
                <field id="EndDate"/>
                <field id="Description"/>
                <field id="NumberOfContacts"/>
                <field id="NumberOfOpportunities"/>
                <field id="NumberOfWonOpportunities"/>
                <field id="AmountAllOpportunities"/>
                <field id="AmountWonOpportunities"/>
                <field id="OwnerId"/>
                <field id="Owner.Name"/>
                <field id="NumberOfResponses"/>
                <field id="CreatedBy.Name"/>
                <field id="LastModifiedBy.Name"/>
                <field id="CreatedById"/>
                <field id="LastModifiedById"/>
                <field id="ParentId"/>
                <field id="IsActive"/>
                <field id="LastModifiedDate"/>
                <field id="Id"/>
                <field id="CreatedDate"/>
                <field id="Campaign_Super_Type__c"/>
                <field id="Campaign_Channel__c"/>
                <field id="Super_Channel__c"/>
                <field id="Product_Focus__c"/>
                <field id="Last_nomination_Date__c"/>
            </fields>
            <conditions>
                <condition type="fieldvalue" value="" field="Id" operator="=" enclosevalueinquotes="true" state="filterableoff" inactive="true" name="Id" model=""/>
            </conditions>
            <actions/>
        </model>
        <model id="CampaignMemberStatuses" limit="" query="false" createrowifnonefound="false" sobject="CampaignMemberStatus" orderby="SortOrder, Label" datasource="salesforce" processonclient="false">
            <fields>
                <field id="IsDefault"/>
                <field id="Label"/>
                <field id="HasResponded"/>
                <field id="SortOrder"/>
            </fields>
            <conditions>
                <condition type="modelmerge" value="" field="CampaignId" operator="=" model="Campaign" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="noquery"/>
            </conditions>
            <actions>
                <action>
                    <actions>
                        <action type="createRow" fieldmodel="Campaign" affectedrows="context" model="CampaignMemberStatuses" appendorprepend="prepend" defaultmodefornewitems="read">
                            <defaults>
                                <default type="fieldvalue" field="Label" fieldtargetobjects="CampaignMemberStatus" enclosevalueinquotes="true" value="Nominated"/>
                            </defaults>
                        </action>
                        <action type="createRow" model="CampaignMemberStatuses" appendorprepend="prepend" defaultmodefornewitems="edit" affectedrows="context">
                            <defaults>
                                <default type="fieldvalue" field="Label" fieldtargetobjects="CampaignMemberStatus" enclosevalueinquotes="true" value="Accepted"/>
                            </defaults>
                        </action>
                        <action type="createRow" model="CampaignMemberStatuses" appendorprepend="prepend" defaultmodefornewitems="edit" affectedrows="context">
                            <defaults>
                                <default type="fieldvalue" field="Label" fieldtargetobjects="CampaignMemberStatus" enclosevalueinquotes="true" value="Rejected"/>
                            </defaults>
                        </action>
                        <action type="save">
                            <models>
                                <model>CampaignMemberStatuses</model>
                            </models>
                        </action>
                    </actions>
                    <events>
                        <event>models.loaded</event>
                    </events>
                </action>
            </actions>
        </model>
        <model id="User" limit="1" query="false" createrowifnonefound="false" sobject="User" processonclient="false" datasource="salesforce">
            <fields>
                <field id="Manager_Name__c"/>
                <field id="Id"/>
            </fields>
            <conditions>
                <condition type="userinfo" value="" field="Id" operator="=" enclosevalueinquotes="true" userinfotype="userid" model=""/>
            </conditions>
            <actions/>
        </model>
        <model id="Leads" limit="10" query="false" createrowifnonefound="false" sobject="Lead" orderby="LastName, FirstName" processonclient="false" datasource="salesforce">
            <fields>
                <field id="Company"/>
                <field id="FirstName"/>
                <field id="LastName"/>
                <field id="LeadSource"/>
                <field id="Title"/>
                <field id="Email"/>
                <field id="Id"/>
            </fields>
            <conditions>
                <condition type="fieldvalue" value="" enclosevalueinquotes="true" field="LeadSource" state="filterableoff" inactive="true" name="LeadSource" model=""/>
                <condition type="join" value="" field="Id" operator="not in" enclosevalueinquotes="true" joinobject="CampaignMember" joinfield="LeadId" state="filterableon" inactive="false" name="LeadsNotInCampaign" model="">
                    <conditions>
                        <condition type="modelmerge" value="" field="CampaignId" operator="=" model="Campaign" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="noquery"/>
                    </conditions>
                </condition>
            </conditions>
            <actions/>
        </model>
        <model id="CampaignMembers_Lead" limit="50" query="false" createrowifnonefound="false" orderby="Lead.LastName,Lead.FirstName" sobject="CampaignMember" datasource="salesforce" processonclient="false">
            <fields>
                <field id="Status"/>
                <field id="HasResponded"/>
                <field id="LeadId"/>
                <field id="Lead.Company"/>
                <field id="Lead.Title"/>
                <field id="Lead.FirstName"/>
                <field id="Lead.LastName"/>
                <field id="Lead.Email"/>
                <field id="Lead.Id"/>
                <field id="CampaignId"/>
                <field id="Campaign.Name"/>
                <field id="Campaign.Id"/>
            </fields>
            <conditions>
                <condition type="param" value="Id" field="CampaignId" operator="=" enclosevalueinquotes="true" novaluebehavior="" model=""/>
                <condition type="blank" value="null" field="ContactId" operator="=" enclosevalueinquotes="false" model=""/>
            </conditions>
            <actions/>
        </model>
        <model id="CampaignMembers_Contact" query="false" createrowifnonefound="false" orderby="Contact.LastName,Contact.FirstName" sobject="CampaignMember" datasource="salesforce" processonclient="false" async="false">
            <fields>
                <field id="ContactId"/>
                <field id="Contact.Email"/>
                <field id="Status"/>
                <field id="HasResponded"/>
                <field id="Contact.Title"/>
                <field id="Contact.AccountId"/>
                <field id="Contact.Account.Name"/>
                <field id="Contact.FirstName"/>
                <field id="Contact.LastName"/>
                <field id="Campaign.Id"/>
                <field id="CampaignId"/>
                <field id="Campaign.Name"/>
                <field id="Added By" uionly="true" displaytype="FORMULA" ogdisplaytype="TEXT" readonly="true" returntype="TEXT" label="Created By">
                    <formula>{{$User.name}}</formula>
                </field>
                <field id="Contact.Job_Level__c"/>
                <field id="Contact.MailingStreet"/>
                <field id="Contact.MailingCountry"/>
                <field id="Contact.MailingCity"/>
                <field id="Contact.MailingState"/>
                <field id="Contact.MailingPostalCode"/>
                <field id="CreatedById"/>
                <field id="CreatedBy.Name"/>
                <field id="Account_Owner__c"/>
                <field id="Contact.Name"/>
                <field id="Contact.OtherAddress"/>
                <field id="Alternate_Address__c"/>
                <field id="Name"/>
            </fields>
            <conditions>
                <condition type="modelmerge" value="" field="CampaignId" operator="=" state="filterableon" inactive="false" name="CampaignId" model="Campaign" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="deactivate"/>
                <condition type="blank" value="null" field="LeadId" operator="=" enclosevalueinquotes="false" model=""/>
                <condition type="fieldvalue" field="CreatedById" operator="=" inactive="true" enclosevalueinquotes="true" name="__autofilter__CreatedById" state="filterableoff" value=""/>
            </conditions>
            <actions>
                <action>
                    <actions>
                        <action type="updateRow" sourcemodel="CampaignMembers_Contact" targetmodel="CampaignMembers_Contact" affectedrows="context" fieldmodel="CampaignMembers_Contact" field="Contact.OtherAddress" enclosevalueinquotes="true"/>
                        <action type="save"/>
                    </actions>
                    <events>
                        <event>row.updated</event>
                    </events>
                    <fields>
                        <field>Alternate Address</field>
                    </fields>
                </action>
            </actions>
        </model>
        <model id="DummyMemberStatus" limit="0" query="false" createrowifnonefound="true" sobject="CampaignMember" processonclient="false" datasource="salesforce">
            <fields>
                <field id="Status"/>
            </fields>
            <conditions/>
            <actions/>
        </model>
        <model query="false" createrowifnonefound="false" datasource="salesforce" id="Generic_junction" sobject="Generic_Junction__c" label="Qualified Accounts">
          &nbs
Photo of Mike Dwyer

Mike Dwyer, Champion

  • 4,622 Points 4k badge 2x thumb
Unfortunately, this xml seems corrupted and does not produce a valid page. Since you have a different use case, it may be appropriate to start a new discussion and explain what you want to do. Re-post the xml there if it illustrates what you are finding unsuccessful. From what I can glean from your xml, you may only need to post the section between <models> and </models>.
Photo of Jaiti

Jaiti

  • 392 Points 250 badge 2x thumb
Hi Mike,
Here is the use case:  I am trying to generate a list of accounts where the associated contact has been added as a campaign member. 

Currently- I have an account model , contact model and campaign model.
A contact associated with account is added as a campaign member and I need an indication on the account that an associated contact is added.

I was hoping that I could use the MODEL_LOOKUP("CampaignMembers_Contact","Id","ContactId",{{Id}})  to display Text onto a UI only field. 

This model look up compares the accountid on the campaign member model with the account id on the account model and where there is a match it stamps text " Account already Added"


Thanks,
Jaiti 

<skuidpage showsidebar="false" showheader="true" tabtooverride="Campaigns" personalizationmode="server" theme="Workday Theme" cachepage="false">
    <resources>
        <labels/>
        <javascript>
            <jsitem location="inlinesnippet" name="CampaignMemberStatus" url="">var field = arguments[0],
    value = skuid.utils.decodeHTML(arguments[1]),
    $ = skuid.$,
    StatusModel,
    hasResponded = field.row.HasResponded || false,
    isMassUpdate = (typeof field.row.HasResponded === 'undefined');

// Find the CampaignMemberStatus model
$.each(skuid.model.list(),function(){
   if (this.objectName === 'CampaignMemberStatus') {
      StatusModel = this;
      return false;
   }
});

if (field.mode!=='edit'){
   skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);
} else {

   var entries = $.map(StatusModel.data,function(item){
       return {
            label: item.Label,
            value: item.Label,
            defaultValue: item.IsDefaultValue,
            isActive: true
       };
   });
    field.element.append(skuid.ui.renderers.PICKLIST.edit({
    value : value,
entries : entries,
renderas : field.options.type,
onChange : function(value) {
field.model.updateRow(field.row,field.id,value,{ initiatorId : field._GUID});
},
required : field.required,
addNoneOption: field.options.addNoneOption,
mode : field.mode,
buttonSetName : field.id + '_' + field._GUID,
noneLabel : field.options.noneLabel
}));
}</jsitem>
            <jsitem location="inlinesnippet" name="saveNewItemsInPopup" cachelocation="false" url="">var $ = skuid.$,
    params = arguments[0],
    component = params.component,
    popup = component.editor.element.closest('.ui-dialog-content'),
    modelsToSave = [],
    objLabelsToSave = [],
    uniqueModels = {};

popup.children().each(function(){
    var obj = $(this).data('object');
    if (obj &amp;&amp; obj.model &amp;&amp; !uniqueModels[obj.model.id]) {
        var model = obj.model;
        modelsToSave.push(model);
        if (model.data &amp;&amp; model.data.length) {
            if (model.data.length&gt;1) {
                objLabelsToSave.push(model.labelPlural);
            } else {
                objLabelsToSave.push(model.label);
            }
        }
        uniqueModels[obj.model.id] = 1;
    }
});

var message = 'Saving new ';
if (objLabelsToSave.length &lt; 3) {
    message += objLabelsToSave.join(' and ');
} else {
    var lastObj = objLabelsToSave.pop();
    message += objLabelsToSave.join(', ');
    message += ', and ' + lastObj;
}
message += '...';
popup.block({
    message: message
});

skuid.model.save(modelsToSave,{callback:function(result){
    if (result.totalsuccess){

        // Refresh the data in related Models on the page
        var uniqueRelatedObjectsToCheck = {},
            relatedModelsToUpdate = [];

        $.each(modelsToSave,function(){
            if (this.objectName &amp;&amp; !uniqueRelatedObjectsToCheck[this.objectName]) {
                uniqueRelatedObjectsToCheck[this.objectName] = 1;
            }
        });

        // Loop over all Models,
        // including the Models we've already saved,
        // and find ones that are on the same objects as the ones we've already saved.
        // Update them if they do not have unsaved changes.
        $.each(skuid.model.list(),function(){
            if (uniqueRelatedObjectsToCheck[this.objectName]
            &amp;&amp; !this.hasChanged) {
                relatedModelsToUpdate.push(this);
            }
        });
        
        $.when(skuid.model.updateData(relatedModelsToUpdate)).then(function(){
            $.each(popup.children(),function(){
                var obj = $(this).data('object');
                if (obj &amp;&amp; obj.unregister) obj.unregister();
            });
            popup.dialog('destroy');

            // Create new Rows in our Models to Save,
            // to prepare for the NEXT time someone creates a new record
            $.each(modelsToSave,function(){
                this.createRow();
            });

        });
    } else {
        popup.unblock();
    }
}});</jsitem>
            <jsitem location="inlinesnippet" name="AddMembers" cachelocation="false">var params = arguments[0],
   $ = skuid.$,
   objectName = params.model.objectName,
   items = params.item ? [params.item] : params.list.getSelectedItems(),
   MembersModel = skuid.model.getModel('CampaignMembers_'+objectName),
   StatusModel = skuid.model.getModel('DummyMemberStatus'),
   Status = StatusModel.getFieldValue(StatusModel.getFirstRow(),'Status',true);

var newRowIds = {};

$.each(items,function(i,item){
    var row = MembersModel.createRow({
        additionalConditions: [
            {
                field: objectName+'Id',
                value:item.row.Id
            },
            {
                field: 'Status',
                value: "Nominated"
            }
        ]    
   });
   MembersModel.updateRow(row,objectName,item.row);
   newRowIds[row.Id]=1;
});

// Refresh the fields in the Members model
// so that they will show the related field data, e.g. Lead.Email, Lead.Title
$.each(MembersModel.registeredLists,function(i,list){
   $.each(list.renderedItems,function(rowId,item){
      if (rowId in newRowIds) {
          item.refreshFields();
      } 
   });
});


   
</jsitem>
            <jsitem location="inlinecomponent" name="CampaignHierarchy" cachelocation="false" url="">var element = arguments[0],
   $ = skuid.$;

// Add our Parent Campaign into our Child Campaigns table,
// so that we have a single Model to interact with
var CCModel = skuid.model.getModel('ChildCampaigns');
var MainModel = skuid.model.getModel('Campaign');
var copyRow = $.extend({},MainModel.getFirstRow());
CCModel.adoptRow(copyRow,{doAppend:false});

//
// Html fragments
//

var mergeRowAsHtml = function(row,template){
  return CCModel.mergeRow(row,template).html();  
};
var mergeGlobalAsHtml = function(template){
  return skuid.utils.merge('global',template,{createFields:true,registerFields:false}).html();  
};

var numberCells = function(row){
    return '&lt;td&gt;' + mergeRowAsHtml(row,'{{NumberOfLeads}}') + '&lt;/td&gt;' + '&lt;td&gt;' + mergeRowAsHtml(row,'{{NumberOfContacts}}') + '&lt;/td&gt;' + '&lt;td&gt;' + mergeRowAsHtml(row,'{{NumberOfResponses}}') + '&lt;/td&gt;' + '&lt;td&gt;' + mergeRowAsHtml(row,'{{NumberOfConvertedLeads}}') + '&lt;/td&gt;' + '&lt;td&gt;' + mergeRowAsHtml(row,'{{AmountWonOpportunities}}') + '&lt;/td&gt;';
};    
    
var mainRowBody = function(row,indent) {
    return '&lt;tr class="nx-item"&gt;'
        // NAME cell
        + '&lt;td&gt;&lt;div class="nx-field ' + indent + '"&gt;&lt;div class="nx-field-text"&gt;'
        + mergeRowAsHtml(row,'{{Name}}')
        + '&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;'
        // NUMBER CELLS
        + numberCells(row)
        + '&lt;/tr&gt;';
};        

var template = 

    '&lt;table class="nx-skootable-data hierarchy-table"&gt;'

    //
    // BODY
    //
    + '&lt;tbody&gt;'

    //
    // Row for the PRIMARY CAMPAIGN
    //

    + '&lt;tr class="nx-item campaign-hierarchy-row1"&gt;'
    
    // NAME CELL
    + '&lt;td&gt;'
    + mergeRowAsHtml(CCModel.getFirstRow(),
        '&lt;div&gt;{{Name}}'
        // If we have a parent Campaign,
        // add a link to view that Parent
        + '{{#ParentId}}'
        + '&lt;div style="display:inline-block;"&gt; (&lt;a href="/{{{ParentId}}}"&gt;View Parent&lt;/a&gt;)&lt;/div&gt;'
        + '{{/ParentId}}'
        + ' '
        + '{{#Id}}'
        + '&lt;div style="display:inline-block;"&gt; (&lt;a href="/p/camp/ViewCampaignHierarchy/d?id={{{Id}}}"&gt;View Hierarchy&lt;/a&gt;)&lt;/div&gt;'
        + '{{/Id}}'
        + '&lt;/div&gt;'
    )
    
    + '&lt;/td&gt;'
    
    // NUMBERS CELLS
    + numberCells(CCModel.getFirstRow())
    
    + '&lt;/tr&gt;';

    //
    // Rows for the Child/Grand-child Campaigns
    //
$.each(CCModel.data,function(i,row){
    if (i===0)return true;// Skip the first row
    template += mainRowBody(row,"indent1");
    if (row.ChildCampaigns &amp;&amp; row.ChildCampaigns.records) {
        $.each(row.ChildCampaigns.records,function(i,cc){
           template += mainRowBody(cc,"indent2");
        });
    }
});

template += 
    '&lt;/tbody&gt;';
    
    // HEADER
    //
template += '&lt;thead&gt;'
    + '&lt;tr&gt;'
    + '{{#$Model.ChildCampaigns}}'
    + '&lt;th&gt;{{fieldsMap.Name.label}}&lt;/th&gt;'
    + '&lt;th&gt;{{fieldsMap.NumberOfLeads.label}}&lt;/th&gt;'
    + '&lt;th&gt;{{fieldsMap.NumberOfContacts.label}}&lt;/th&gt;'
    + '&lt;th&gt;{{fieldsMap.NumberOfResponses.label}}&lt;/th&gt;'
    + '&lt;th&gt;{{fieldsMap.NumberOfConvertedLeads.label}}&lt;/th&gt;'
    + '&lt;th&gt;{{fieldsMap.AmountWonOpportunities.label}}&lt;/th&gt;'
    + '{{/$Model.ChildCampaigns}}'
    + '&lt;/tr&gt;'
    + '&lt;/thead&gt;'

    //
    // TFOOT
    //
    + '&lt;tfoot&gt;'
    + '&lt;tr&gt;'
    + '&lt;th&gt;Hierarchy Total&lt;/th&gt;'
    + '&lt;th&gt;'+mergeRowAsHtml(CCModel.getFirstRow(),'{{HierarchyNumberOfLeads}}')+'&lt;/th&gt;'
    + '&lt;th&gt;'+mergeRowAsHtml(CCModel.getFirstRow(),'{{HierarchyNumberOfContacts}}')+'&lt;/th&gt;'
    + '&lt;th&gt;'+mergeRowAsHtml(CCModel.getFirstRow(),'{{HierarchyNumberOfResponses}}')+'&lt;/th&gt;'
    + '&lt;th&gt;'+mergeRowAsHtml(CCModel.getFirstRow(),'{{HierarchyNumberOfConvertedLeads}}')+'&lt;/th&gt;'
    + '&lt;th&gt;'+mergeRowAsHtml(CCModel.getFirstRow(),'{{HierarchyAmountWonOpportunities}}')+'&lt;/th&gt;'
    + '&lt;/tr&gt;'
    + '&lt;/tfoot&gt;';
    
template += '&lt;/table&gt;';

element.html(skuid.utils.merge('global',template,{createFields:true}).html());</jsitem>
        </javascript>
        <css>
            <cssitem location="inline" name="hierarchy table" cachelocation="false">.hierarchy-table .indent1 {
    padding-left: 3.0em;
}

.hierarchy-table .indent2 {
    padding-left: 6.0em;
}

.hierarchy-table tfoot {
    background-color: #f2e7d1;
}

.campaign-hierarchy-row1 .nx-field {
    display:inline-block;
}

.nx-skootable-data tbody .nx-item.campaign-hierarchy-row1 td {
    background-color: #fffcf3;
}</cssitem>
        </css>
        <actionsequences uniqueid="sk-To7-1431"/>
    </resources>
    <models>
        <model id="Campaign" limit="1" query="false" createrowifnonefound="false" orderby="" sobject="Campaign" datasource="salesforce" processonclient="false">
            <fields>
                <field id="Name"/>
                <field id="Type"/>
                <field id="Status"/>
                <field id="StartDate"/>
                <field id="EndDate"/>
                <field id="Description"/>
                <field id="NumberOfContacts"/>
                <field id="NumberOfOpportunities"/>
                <field id="NumberOfWonOpportunities"/>
                <field id="AmountAllOpportunities"/>
                <field id="AmountWonOpportunities"/>
                <field id="OwnerId"/>
                <field id="Owner.Name"/>
                <field id="NumberOfResponses"/>
                <field id="CreatedBy.Name"/>
                <field id="LastModifiedBy.Name"/>
                <field id="CreatedById"/>
                <field id="LastModifiedById"/>
                <field id="ParentId"/>
                <field id="IsActive"/>
                <field id="LastModifiedDate"/>
                <field id="Id"/>
                <field id="CreatedDate"/>
                <field id="Campaign_Super_Type__c"/>
                <field id="Campaign_Channel__c"/>
                <field id="Super_Channel__c"/>
                <field id="Product_Focus__c"/>
                <field id="Last_nomination_Date__c"/>
            </fields>
            <conditions>
                <condition type="fieldvalue" value="" field="Id" operator="=" enclosevalueinquotes="true" state="filterableoff" inactive="true" name="Id" model=""/>
            </conditions>
            <actions/>
        </model>
        <model id="CampaignMemberStatuses" limit="" query="false" createrowifnonefound="false" sobject="CampaignMemberStatus" orderby="SortOrder, Label" datasource="salesforce" processonclient="false">
            <fields>
                <field id="IsDefault"/>
                <field id="Label"/>
                <field id="HasResponded"/>
                <field id="SortOrder"/>
            </fields>
            <conditions>
                <condition type="modelmerge" value="" field="CampaignId" operator="=" model="Campaign" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="noquery"/>
            </conditions>
            <actions>
                <action>
                    <actions>
                        <action type="createRow" fieldmodel="Campaign" affectedrows="context" model="CampaignMemberStatuses" appendorprepend="prepend" defaultmodefornewitems="read">
                            <defaults>
                                <default type="fieldvalue" field="Label" fieldtargetobjects="CampaignMemberStatus" enclosevalueinquotes="true" value="Nominated"/>
                            </defaults>
                        </action>
                        <action type="createRow" model="CampaignMemberStatuses" appendorprepend="prepend" defaultmodefornewitems="edit" affectedrows="context">
                            <defaults>
                                <default type="fieldvalue" field="Label" fieldtargetobjects="CampaignMemberStatus" enclosevalueinquotes="true" value="Accepted"/>
                            </defaults>
                        </action>
                        <action type="createRow" model="CampaignMemberStatuses" appendorprepend="prepend" defaultmodefornewitems="edit" affectedrows="context">
                            <defaults>
                                <default type="fieldvalue" field="Label" fieldtargetobjects="CampaignMemberStatus" enclosevalueinquotes="true" value="Rejected"/>
                            </defaults>
                        </action>
                        <action type="save">
                            <models>
                                <model>CampaignMemberStatuses</model>
                            </models>
                        </action>
                    </actions>
                    <events>
                        <event>models.loaded</event>
                    </events>
                </action>
            </actions>
        </model>
        <model id="User" limit="1" query="false" createrowifnonefound="false" sobject="User" processonclient="false" datasource="salesforce">
            <fields>
                <field id="Manager_Name__c"/>
                <field id="Id"/>
            </fields>
            <conditions>
                <condition type="userinfo" value="" field="Id" operator="=" enclosevalueinquotes="true" userinfotype="userid" model=""/>
            </conditions>
            <actions/>
        </model>
        <model id="Leads" limit="10" query="false" createrowifnonefound="false" sobject="Lead" orderby="LastName, FirstName" processonclient="false" datasource="salesforce">
            <fields>
                <field id="Company"/>
                <field id="FirstName"/>
                <field id="LastName"/>
                <field id="LeadSource"/>
                <field id="Title"/>
                <field id="Email"/>
                <field id="Id"/>
            </fields>
            <conditions>
                <condition type="fieldvalue" value="" enclosevalueinquotes="true" field="LeadSource" state="filterableoff" inactive="true" name="LeadSource" model=""/>
                <condition type="join" value="" field="Id" operator="not in" enclosevalueinquotes="true" joinobject="CampaignMember" joinfield="LeadId" state="filterableon" inactive="false" name="LeadsNotInCampaign" model="">
                    <conditions>
                        <condition type="modelmerge" value="" field="CampaignId" operator="=" model="Campaign" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="noquery"/>
                    </conditions>
                </condition>
            </conditions>
            <actions/>
        </model>
        <model id="CampaignMembers_Lead" limit="50" query="false" createrowifnonefound="false" orderby="Lead.LastName,Lead.FirstName" sobject="CampaignMember" datasource="salesforce" processonclient="false">
            <fields>
                <field id="Status"/>
                <field id="HasResponded"/>
                <field id="LeadId"/>
                <field id="Lead.Company"/>
                <field id="Lead.Title"/>
                <field id="Lead.FirstName"/>
                <field id="Lead.LastName"/>
                <field id="Lead.Email"/>
                <field id="Lead.Id"/>
                <field id="CampaignId"/>
                <field id="Campaign.Name"/>
                <field id="Campaign.Id"/>
            </fields>
            <conditions>
                <condition type="param" value="Id" field="CampaignId" operator="=" enclosevalueinquotes="true" novaluebehavior="" model=""/>
                <condition type="blank" value="null" field="ContactId" operator="=" enclosevalueinquotes="false" model=""/>
            </conditions>
            <actions/>
        </model>
        <model id="CampaignMembers_Contact" query="false" createrowifnonefound="false" orderby="Contact.LastName,Contact.FirstName" sobject="CampaignMember" datasource="salesforce" processonclient="false" async="false">
            <fields>
                <field id="ContactId"/>
                <field id="Contact.Email"/>
                <field id="Status"/>
                <field id="HasResponded"/>
                <field id="Contact.Title"/>
                <field id="Contact.AccountId"/>
                <field id="Contact.Account.Name"/>
                <field id="Contact.FirstName"/>
                <field id="Contact.LastName"/>
                <field id="Campaign.Id"/>
                <field id="CampaignId"/>
                <field id="Campaign.Name"/>
                <field id="Added By" uionly="true" displaytype="FORMULA" ogdisplaytype="TEXT" readonly="true" returntype="TEXT" label="Created By">
                    <formula>{{$User.name}}</formula>
                </field>
                <field id="Contact.Job_Level__c"/>
                <field id="Contact.MailingStreet"/>
                <field id="Contact.MailingCountry"/>
                <field id="Contact.MailingCity"/>
                <field id="Contact.MailingState"/>
                <field id="Contact.MailingPostalCode"/>
                <field id="CreatedById"/>
                <field id="CreatedBy.Name"/>
                <field id="Account_Owner__c"/>
                <field id="Contact.Name"/>
                <field id="Contact.OtherAddress"/>
                <field id="Alternate_Address__c"/>
                <field id="Name"/>
            </fields>
            <conditions>
                <condition type="modelmerge" value="" field="CampaignId" operator="=" state="filterableon" inactive="false" name="CampaignId" model="Campaign" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="deactivate"/>
                <condition type="blank" value="null" field="LeadId" operator="=" enclosevalueinquotes="false" model=""/>
                <condition type="fieldvalue" field="CreatedById" operator="=" inactive="true" enclosevalueinquotes="true" name="__autofilter__CreatedById" state="filterableoff" value=""/>
            </conditions>
            <actions>
                <action>
                    <actions>
                        <action type="updateRow" sourcemodel="CampaignMembers_Contact" targetmodel="CampaignMembers_Contact" affectedrows="context" fieldmodel="CampaignMembers_Contact" field="Contact.OtherAddress" enclosevalueinquotes="true"/>
                        <action type="save"/>
                    </actions>
                    <events>
                        <event>row.updated</event>
                    </events>
                    <fields>
                        <field>Alternate Address</field>
                    </fields>
                </action>
            </actions>
        </model>
        <model id="DummyMemberStatus" limit="0" query="false" createrowif