Can a button affect the values in fields?

PeterPeter Member
edited June 2019 in Questions
I have a picklist of a bunch of statuses (new, submitted, rejected, in progress, etc.), but ideally the user should only be able to choose one (submitted) or leave it alone (new, or approved). Is there a way to make a button on a Skuid page that changes the value in a field on that page to something specific (and then even saves the page, perhaps)? Then the user doesn't have to click on a field and then choose a value in the field, they can just click once. Right now I'm contemplating adding a new picklist field that has only the two the values in it, then a workflow that can update the main status field once they save their changes, since there isn't a good way to limit which values the user can choose in a picklist field. Obviously that's hokey, though, and doesn't improve the UI experience, either.

Comments

  • Zach McElrathZach McElrath Skuad
    edited June 2019
    This is doable with a JavaScript Snippet. If your button (Page Title, Table Row/Global/Mass Action, Wizard, or unattached) is set to the type of "Custom", then you can specify the name of a Snippet to execute. Supposing that the Object you want to update is Case, and you have a Model called "CaseData", with one row in it, and you want to update the "Status" field to be a certain value, e.g. 'Escalated', and then want to immediately save that Model, here's what your snippet code would look like:
      var CaseModel = skuid.model.getModel('CaseData');  var CaseRow = CaseModel.getFirstRow();  CaseModel.updateRow(CaseRow,'Status','Escalated');  CaseModel.save();  
  • PeterPeter Member
    edited November 2015
    Awesome - so easy! Every time you post a solution like this it gets me more excited to see a reference for the Skuid object model, so I can figure more of these things out myself, and come up with cool enhancements. Extrapolating from this will become very handy.
  • Thaddeus WardThaddeus Ward Member
    edited March 2017
    Can I used this same method to update multiple fields? How would the code look for that?
  • Kaede HollandKaede Holland Member ✭✭
    edited August 2014
    This is cool, you guys!
  • Zach McElrathZach McElrath Skuad
    edited December 2016
    The best way to update multiple fields is to use a version of updateRow which passes in the field/value pairings as a JavaScript object:
      var CaseModel = skuid.model.getModel('CaseData');  var CaseRow = CaseModel.getFirstRow();  CaseModel.updateRow(CaseRow,{     'Status' : 'Escalated',     'Priority' : 'High',     'My_Custom_Field__c' : 'Hello World',     'OwnerId' : skuid.utils.userInfo.userId  });  CaseModel.save();  
  • Thaddeus WardThaddeus Ward Member
    edited November 2013
    Excellent. This makes great sense.
  • Ashley ErhartAshley Erhart Member
    edited December 2016
    Is there any way to accomplish this same thing without javascript? Specifically, creating a button that each time you click it moves the record through the picklist options for Status. So first click, changes from "New" to "In Progress" and second click changes from "In Progress" to "Complete", etc
  • DaveDave Member ✭✭
    edited March 2018
    Hi Ashley, you could do it quite simply actually

    Using your example, Create 2 button 

    1st button: add action to Change it to "In Progress" + save and a rendering condition to only make it appear it when field = "New"

    2nd button: add action to Change it to "Complete" + save  and a rendering condition to only make it appear it when field= "In Progress"

    And so on...

    For the end user they will never see the difference, as only 1 button would appear at a time

    Hope it helps :)

  • Ashley ErhartAshley Erhart Member
    edited December 2016
    Thank you!
Sign In or Register to comment.