Important Update: Community URLs redirect issues are partially resolved. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

How to make Custom Object Button Change Value in Values List

AmyJoJarboe
Contributor III

Hello All,

I'm still very new to Archer, but I'm trying to make a Custom Object Button that will change a value in a values list. I've seen a lot of samples, but they don't make much sense. Can someone please break this down very simply for me? I can create a button, I'm just really struggling on creating JavaScript that works to change a value in a values list.

Thank you!

25 REPLIES 25

GeoffTaylor2
Contributor III

If all the button needs to do is set the value, and you're setting it to the same value every time, you can just set the "onclick" attribute of your button to
$CM.setFieldValue(11111, [22222], '');

 

Your custom object would look something like this:

 

<div style="text-align:center;"><img src="../BackgroundImageGenerator.axd?className=StyledButton&classProperties=caption:Set Value;iconSetStyle:VistaRound;baseColor:%23DDDDDD;disabled:False" onclick="$CM.setFieldValue(11111, [22222], '');"></div>

 

In setFieldValue, the first parameter is the ID of the field whose value you want to set, the second parameter is an array of value IDs, and the last parameter is the "other" text.

 

If the field only accepts one value, pass an array of one item as the second parameter.

If you have Require users to enter supporting information when they select this value enabled for the value, pass the desired "other" text as the third parameter. If not, pass an empty string as the third parameter.

This is fantastic, thank you! I do have a question:

  • So I put in this line, and altered it appropriately (I think). However, it's still not working. For my field ID, I put in the long string that was listed as the ID for the Values List. For my array of value IDs, I just did [1]. So that portion of my command looked like: $CM.setFieldValue(F8....., [1]). Why isn't this working?

Amy Jo Jarboe‌,

 

You are passing incorrect parameters. You can get the Field ID by hovering your cursor over the field you wanted to update in the Fields tab of the application of your interest. You will see the Field ID in the bottom right corner of your screen. Pass this as the first parameter to the "setFieldValue()".

 

Below example, hovering the mouse over the field [Application Type] shows the field ID as "2825" in the bottom right corner.

pastedImage_1.png

 

You can get the Value ID within the field "Values" tab. Click the Values list field you wanted to update. Navigate to the "Values" tab. Hover your mouse over the value you wanted to update. You will see the Value ID in the bottom right corner of the screen.

 

Below example shows the Value ID of "Web App" values as "68695".

 

pastedImage_2.png

 

Based on the above example, your script may look like:

pastedImage_2.png

Thank you! Now I have a different problem: when I click the button, the dropdown appears, but it doesn't select the value?

Amy Jo Jarboe‌,

 

It works for me. You can actually put the field id in a different variable, if you want - but that doesn't make any difference.

 

pastedImage_1.png

Amy, try changing to values list from Drop Down to Values Popup instead.

 Advisory Consultant

Hi David, so I tried that and I am running into the same issues. Can I just use that one line of code that Geoff provided, or would I need to also include Arun's code?

Amy Jo Jarboe‌ Can you post your custom object code?

Amy, here's the complete code to set a values list field.

 

The statusFieldId is the values list field id and the statusSubmit is the id of the value you're trying t set.

<div class="toolbar-app-buttons-left">
     <a title="Set Value" class="tb-btn-link-left" id="btnSetValue" href="javascript&colon;void(0);" data-check-dirty="false">
          <div class="tb-btn" data-icon="&#xE348" data-icon-pos="left">Set Value</div>
     </a>
</div>

<script type="text/javascript">
     var integration = {
          statusFieldId:"13959",
          statusSubmit:"55809"
     };

     $('#btnSetValue').click(function(){
        UpdateValuesList(integration.statusFieldId, integration.statusSubmit);
     });

     function UpdateValuesList(changeId, assignedValue) {
        var valueArray = new Array(1);
        valueArray[0] = assignedValue;
        $CM.setFieldValue(changeId, valueArray, '');
     }
</script>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 Advisory Consultant