Skip to main content

In salesforce we are using a year picklist which is having a values 2015,2016,2017. 
Every year i am adding a new picklist value. Can anyone help me with some javascript code to add a new value every year dynamically? 

Mahender,


Can you use the Salesforce date literals for the condition? That is instead of prompting for 2017 or 2018. Prompt for ‘This Year’ or ‘Last Year’. These will always work and never need updating.


Here is a sample page that demonstrates this using Tasks:


<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" showheader="true" tabtooverride="Task">
<models>
<model id="TaskOwners" limit="" query="true" createrowifnonefound="false" adapter="" type="aggregate" sobject="Task">
<fields/>
<conditions/>
<actions/>
<groupby method="simple">
<field id="OwnerId" name="ownerId"/>
<field id="Owner.Name" name="ownerName"/>
</groupby>
</model>
<model id="CurrentUser" limit="1" query="true" createrowifnonefound="false" type="" sobject="User" datasource="salesforce">
<fields>
<field id="Id"/>
<field id="Name"/>
</fields>
<conditions>
<condition type="userinfo" value="" field="Id" operator="=" enclosevalueinquotes="true" userinfotype="userid"/>
</conditions>
<actions/>
</model>
<model id="Task" limit="20" query="false" createrowifnonefound="false" sobject="Task" type="" datasource="salesforce">
<fields>
<field id="Subject"/>
<field id="CreatedDate"/>
<field id="ActivityDate"/>
<field id="OwnerId"/>
<field id="Owner.Name"/>
<field id="PlusSevenDays" uionly="true" displaytype="FORMULA" label="PlusSevenDays" ogdisplaytype="TEXT" readonly="true" returntype="DATE" precision="9" scale="2">
<formula>(((({{ActivityDate}} - TODAY())/(1000*60*60*24)) + 7)*(1000*60*60*24) + TODAY())</formula>
</field>
</fields>
<conditions>
<condition type="fieldvalue" value="" enclosevalueinquotes="true" field="OwnerId" state="filterableoff" inactive="true" name="OwnerId"/>
<condition type="fieldvalue" value="" enclosevalueinquotes="false" field="CreatedDate" state="filterableoff" inactive="true" name="CreatedDate"/>
</conditions>
<actions/>
</model>
</models>
<components>
<pagetitle model="Task" uniqueid="sk-V1Gna-74">
<maintitle>
<template>{{Model.labelPlural}}</template>
</maintitle>
<subtitle>
<template>Home</template>
</subtitle>
<actions>
<action type="savecancel" uniqueid="sk-24dfIs-192"/>
</actions>
</pagetitle>
<tabset rememberlastusertab="true" defertabrendering="true" uniqueid="sk-15p-yE-85" renderas="">
<tabs>
<tab name="Tasks">
<components>
<skootable showconditions="true" showsavecancel="false" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="true" model="Task" mode="read" uniqueid="sk-V1Gna-75">
<fields>
<field id="Subject" allowordering="true" uniqueid="sk-24dfJC-201"/>
<field id="ActivityDate" valuehalign="" type="" uniqueid="sk-24dfJF-204"/>
<field id="PlusSevenDays" hideable="true" uniqueid="fi-27u_lq-447" valuehalign="" type=""/>
<field id="CreatedDate" allowordering="true" uniqueid="sk-24dfJI-207" valuehalign="" type=""/>
<field id="OwnerId" uniqueid="sk-24dfJK-210"/>
</fields>
<rowactions>
<action type="edit"/>
<action type="delete"/>
</rowactions>
<massactions usefirstitemasdefault="true">
<action type="massupdate"/>
<action type="massdelete"/>
</massactions>
<views>
<view type="standard"/>
</views>
<filters>
<filter type="select" filteroffoptionlabel="All Users" createfilteroffoption="true" affectcookies="true" autocompthreshold="25" conditionsource="manual" labelmode="no" condition="OwnerId" filtermethod="server">
<sources>
<source type="model" effectsbehavior="justdefault" model="TaskOwners">
<labeltemplate>{{ownerName}}</labeltemplate>
<valuetemplate>{{ownerId}}</valuetemplate>
</source>
</sources>
</filter>
<filter type="select" filteroffoptionlabel="Any CreatedDate" createfilteroffoption="true" affectcookies="false" autocompthreshold="25" conditionsource="manual" filtermethod="server" labelmode="no" condition="CreatedDate">
<sources>
<source type="manual" effectsbehavior="justdefault">
<options>
<option label="This Year" type="simple" value="THIS_YEAR"/>
<option label="Last Year" type="simple" value="LAST_YEAR"/>
<option label="Two Years Ago" type="simple" value="N_YEARS_AGO:2"/>
</options>
</source>
</sources>
</filter>
</filters>
</skootable>
</components>
<oninitialshowactions>
<action type="setCondition" model="Task" condition="OwnerId" value="{{$Model.CurrentUser.data.0.Id}}"/>
<action type="requeryModel" model="Task" behavior="standard"/>
</oninitialshowactions>
<onshowactions>
<action type="requeryModel" model="Task" behavior="standard"/>
</onshowactions>
</tab>
</tabs>
</tabset>
</components>
<resources>
<labels/>
<css/>
<javascript/>
<actionsequences uniqueid="sk-27ulVU-259"/>
</resources>
<styles>
<styleitem type="background" bgtype="none"/>
</styles>
</skuidpage>

Thanks,


Bill


Hi Bill,

Thanks for the reply. My requirement is user should able to select the value from drop down and every year i don't want a new pick list value.

This is my below code. Now how can I add new picklist value dynamically.




































Mahender,

Is ‘Year__c’ the field you are filtering on?

What type of field are you filtering is it?  Text, Date, Date/Time, Picklist?

Thanks,

Bill


Hi Bill,

year__c is pick list field in salesforce. This picklist is having values from 2000 to 2017.

Every year I should a new picklist value now 2018 next year 2019.

is there any way from java script can we add new value(current year) in skuid page so that user can select 2018 and I need not add a new picklist value every year.  


Mahender,


You can do this without code. Take a look at the CallTypeFilter model and the filter on Call Type on this Task table. The CallTypeFilter model is an Aggregate based on Task grouped by the CallType.


You can do the same on your object for the Year__c field. Then use this ‘filter’ model to provide the ‘select’ options for your filter. Note that the filter needs to reference the ‘name’ of the grouped by field (and not the field name itself). On my sample page the groupby field xml is this:


            <field id="CallType" name="callType"/>

When I setup my filter, I reference the groupby ‘name’ → callType


Here is a picture of the setup of my filter:


<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" showheader="true" tabtooverride="Task">
<models>
<model id="CallTypeFilter" limit="" query="true" createrowifnonefound="false" datasource="salesforce" type="aggregate" sobject="Task">
<fields/>
<conditions/>
<actions/>
<groupby method="simple">
<field id="CallType" name="callType"/>
</groupby>
</model>
<model id="TaskOwners" limit="" query="true" createrowifnonefound="false" type="aggregate" sobject="Task" datasource="salesforce">
<fields/>
<conditions/>
<actions/>
<groupby method="simple">
<field id="OwnerId" name="ownerId"/>
<field id="Owner.Name" name="ownerName"/>
</groupby>
</model>
<model id="CurrentUser" limit="1" query="true" createrowifnonefound="false" type="" sobject="User" datasource="salesforce">
<fields>
<field id="Id"/>
<field id="Name"/>
</fields>
<conditions>
<condition type="userinfo" value="" field="Id" operator="=" enclosevalueinquotes="true" userinfotype="userid"/>
</conditions>
<actions/>
</model>
<model id="Task" limit="20" query="false" createrowifnonefound="false" sobject="Task" type="" datasource="salesforce">
<fields>
<field id="Subject"/>
<field id="CreatedDate"/>
<field id="ActivityDate"/>
<field id="OwnerId"/>
<field id="Owner.Name"/>
<field id="CallType"/>
</fields>
<conditions>
<condition type="fieldvalue" value="" enclosevalueinquotes="true" field="OwnerId" state="filterableoff" inactive="true" name="OwnerId"/>
<condition type="fieldvalue" value="" enclosevalueinquotes="false" field="CreatedDate" state="filterableoff" inactive="true" name="CreatedDate"/>
<condition type="fieldvalue" value="" enclosevalueinquotes="true" field="CallType" state="filterableoff" inactive="true" name="CallType"/>
</conditions>
<actions/>
</model>
</models>
<components>
<pagetitle model="Task" uniqueid="sk-V1Gna-74">
<maintitle>
<template>{{Model.labelPlural}}</template>
</maintitle>
<subtitle>
<template>Home</template>
</subtitle>
<actions>
<action type="savecancel" uniqueid="sk-24dfIs-192"/>
</actions>
</pagetitle>
<tabset rememberlastusertab="true" defertabrendering="true" uniqueid="sk-15p-yE-85" renderas="">
<tabs>
<tab name="Tasks">
<components>
<skootable showconditions="true" showsavecancel="false" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="true" model="Task" mode="read" uniqueid="sk-V1Gna-75">
<fields>
<field id="Subject" allowordering="true" uniqueid="sk-24dfJC-201"/>
<field id="ActivityDate" valuehalign="" type="" uniqueid="sk-24dfJF-204"/>
<field id="CreatedDate" allowordering="true" uniqueid="sk-24dfJI-207" valuehalign="" type=""/>
<field id="CallType" hideable="true" uniqueid="fi-3Xyidk-592"/>
<field id="OwnerId" uniqueid="sk-24dfJK-210"/>
</fields>
<rowactions>
<action type="edit"/>
<action type="delete"/>
</rowactions>
<massactions usefirstitemasdefault="true">
<action type="massupdate"/>
<action type="massdelete"/>
</massactions>
<views>
<view type="standard"/>
</views>
<filters>
<filter type="select" filteroffoptionlabel="All Users" createfilteroffoption="true" affectcookies="true" autocompthreshold="25" conditionsource="manual" labelmode="no" condition="OwnerId" filtermethod="server">
<sources>
<source type="model" effectsbehavior="justdefault" model="TaskOwners">
<labeltemplate>{{ownerName}}</labeltemplate>
<valuetemplate>{{ownerId}}</valuetemplate>
</source>
</sources>
</filter>
<filter type="select" filteroffoptionlabel="Any CreatedDate" createfilteroffoption="true" affectcookies="false" autocompthreshold="25" conditionsource="manual" filtermethod="server" labelmode="no" condition="CreatedDate">
<sources>
<source type="manual" effectsbehavior="justdefault">
<options>
<option label="This Year" type="simple" value="THIS_YEAR"/>
<option label="Last Year" type="simple" value="LAST_YEAR"/>
<option label="Two Years Ago" type="simple" value="N_YEARS_AGO:2"/>
</options>
</source>
</sources>
</filter>
<filter type="select" filteroffoptionlabel="All Call Types" createfilteroffoption="true" affectcookies="false" autocompthreshold="25" conditionsource="manual" filtermethod="server" labelmode="no" condition="CallType">
<sources>
<source type="model" effectsbehavior="justdefault" model="CallTypeFilter">
<labeltemplate>{{{callType}}}</labeltemplate>
<valuetemplate>{{callType}}</valuetemplate>
</source>
</sources>
</filter>
</filters>
</skootable>
</components>
<oninitialshowactions>
<action type="setCondition" model="Task" condition="OwnerId" value="{{$Model.CurrentUser.data.0.Id}}"/>
<action type="requeryModel" model="Task" behavior="standard"/>
</oninitialshowactions>
<onshowactions>
<action type="requeryModel" model="Task" behavior="standard"/>
</onshowactions>
</tab>
</tabs>
</tabset>
</components>
<resources>
<labels/>
<css/>
<javascript/>
<actionsequences uniqueid="sk-27ulVU-259"/>
</resources>
<styles>
<styleitem type="background" bgtype="none"/>
</styles>
</skuidpage>