How to modify data in a ConfiForm using and Edit Control macro with JavaScript

Kathleen Janiszewski
Contributor
March 6, 2023

I'm trying to modify fields within a ConfiForm based on the values of other fields using the Edit Control.  Specifically, I'm trying to update the hours a user scheduled to work on a specific project for a certain range of weeks.  I have tried using IFTTT macros with the onModified event.  However, I haven't been successful at getting access to the Form.  That seems strange, since the form defintion is on this page.  I have also tried the Run custom JavaScript option with SetValueFunc(formName, formId) on the Rules for Field Definitions, and apply them to the 3 fields that matter in the calculation (I've also tried all of the fields), but I get strange results.  For example, if I change the hours for myself for weeks 15 - 30, sometimes it works, but sometimes it just updates the rest of the fiscal year with the new hours.  Sometimes I change the scheduled hours, but it doesn't update, so I change it to a different number, but it then updates it with the 2nd number I entered - kind of 1 behind on the form entry.  I need this to update correctly every time.  I started with using the REST API, but that won't update on the TableView macro that shows all of the data of all of the users.  I need all the data to update accurately every time.

Thanks,

-Kathleen

1 answer

1 accepted

1 vote
Answer accepted
Alex Medved _ConfiForms_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 6, 2023

Hi @Kathleen Janiszewski and welcome to community

I will try my best, but honestly - I am very puzzled with your question

Seems to be a mixture of client side and server side things

So, you can update ConfiForms records with ConfiForms IFTTTs (server side) and you can also use REST APIs to update ConfiForms records from a client side

These are different approaches/methods on how to do a similar (or same) thing - should not be used together (and are independent from each other)

Alex

Kathleen Janiszewski
Contributor
March 6, 2023

Alex,

Let me explain what's going on.  I start with a ConfiForm that has a user, number of hours per week, and a list of start weeks and end weeks in the fiscal year.  An admin can at any time change the number of hours per week a user is assigned to their project for a given time frame by week.  Based on the selected weeks, I know which ConfiForm fields need to be updated.  This is where I construct the string that's used in the REST API.  If you have a more direct way for me to be able to update the data directly via the IFTTT macro, please let me know!  That's what I've been looking for.

Thanks.

-Kathleen

Alex Medved _ConfiForms_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 6, 2023

What is the easiest for you. If you find the REST API call easier then do that

I think using the Create/Update ConfiForms Entry or Update Entries by Filter IFTTTs is easier to use and work server side, which means - always (even when updates are invoked from automation, etc)

Alex

Kathleen Janiszewski
Contributor
March 7, 2023

I would much rather do this using the "Update Confiforms by Entry".  I initially tried that.  The limitation is that I need to build the list of fieldnames.  Fine, I've done that plenty of times in JavaScript.  So now, depending on the weeks the user has selected, say weeks 30-45 (i.e., [entry.startweek] is 30 and [entry.endweek] is 45), I only want: "week30=[entry.hours]&week31=[entry.hours]...&week45=[entry.hours]".  This string is pretty easy to create in a loop.  How do I get this into the "Parameters to set on the entry field?"  Is there a way to use the "Set custom name for this action result?"  That's all I see as a field on the ConfiFoms IFTTT Integration rules macro when I select Run JavaScript.

Thanks.

-Kathleen

Alex Medved _ConfiForms_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 7, 2023

Hi

If you need to build the parameters dynamically then you better stay with REST APIs

Alex

Like Kathleen Janiszewski likes this
Kathleen Janiszewski
Contributor
March 7, 2023

Alex,

So now I have the ConfiForm storing the correct data, using the REST API.  Now, I need to force the refresh of the TableView macro.  How can I accomplish that?  I tried adding another onModified IFTTT macro that redirects to the current URL, but that doesn't always work for all of the data.  It's probably an issue with synchronicity.  Please let me know if there are any other options. 

Thank you.

-Kathleen

Alex Medved _ConfiForms_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 7, 2023

Hard to tell what does not always work... without seeing complete configuration, but

If you do everything in JavaScript then I believe there is no need to switch to IFTTT to do just a redirect

You can do the redirect in JavaScript as well. using document.location = 'some url';

Alex

Kathleen Janiszewski
Contributor
March 8, 2023

Alex,

Using location.reload() in the javascript after an update puts me in an infinite loop of re-executing the javascript in the IFTTT macro.  That makes sense though, since once tableview macro is updated with the new data, it's considered an 'update' and fires the IFTTT macro again.  Is there any way to force the update of the data within the TableView macro?

Thank you.

-Kathleen

Alex Medved _ConfiForms_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 8, 2023

If your IFTTT runs onModified and does not have any condition set then it is a problem.

Your IFTTT should have a condition or catch the transition and not run every time on every update

Alex

Kathleen Janiszewski
Contributor
March 8, 2023

The user would only edit and not cancel out unless they modified something, so there's no good reason to have a condition set.  If there's some flag that is set when something changes on the form, that might work.  Otherwise, my initial approach was to do all of this on the initial update form.  Hence the question I pose here: https://community.atlassian.com/t5/Confluence-questions/How-to-use-data-on-a-ConfiForm-to-update-hidden-fields-prior-to/qaq-p/2293599

I'm kind of at the point of giving up on ConfiForms and just do everything in JavaScript with a  Tabulator in lieu of a the TableView macro, and a modal dialog box to server as the form for updates.  I know that will work.

Alex Medved _ConfiForms_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 8, 2023

Well it all depends on what you feel more comfortable with and what is the best tool for the job

From fragmented requirements I read from your posts I feel like this is not really a job for ConfiForms. 

As this is some very custom form that you need to do lots of precalculations.

Anyway 

If there's some flag that is set when something changes on the form, that might work.

You can set one extra field that will tell you such "flag" And never do an update when this field is matching

See this page https://wiki.vertuna.com/display/TEST/Send+email+when+action+button+is+clicked

We send an email only when send field has a true value and only when it changes to true

We have an extra ifttt that resets the send field value after that

Alex

Like Kathleen Janiszewski likes this
Kathleen Janiszewski
Contributor
March 9, 2023

Alex,

Thank you for your help.  You might be right.  I do have to use ConfiForms for parts of this project.

Thanks!

-Kathleen

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events