Hi! I’m currently working on creating forge custom field types. My goal is to create a custom field type which is calculates the time difference between two “Date” or “Datetime” type custom fields. So, I created a context-config page where I can configure custom field config.
In my context config, there are 2 selects where I can select my date or datetime custom fields. When onSubmit event triggered, I store custom field name via Storage API. And I get my stored data at my view.jsx and do calculations and actually it works pretty good.
The issue is when I try to create a new custom field with my custom field type, both of my new and previous custom fields take my last custom field’s configuration even their configurations are different because of storage api.
The problem is obviously clear above. But I need a logical approach to solve this problem from this experienced community.
I am working on a similar issue at the moment. My approach is to set up a trigger module that listens to new custom fields and custom field contexts and then uses the api to set up a default config. I am still debugging my manifest since my trigger doesn’t seem to be triggering yet but I think that approach should work
But I need to know how can I get this value at my view.jsx.
I created a simple example which is goal is showing selected value from context-config in a custom field.
For example;
Let’s say my context-config.jsx is like that:
As stated in the documentation, the configuration variable is not available in the extension context. You will need to fetch it using the Get custom field configurations REST API, providing the issue ID (which in turn you do have in the context) in the query param.
Okay, but this request needs fieldIdOrKey. When I was developing some other custom fields based on issueId, the below code was enough to grab current issue’s id.
@kkercz , thanks for your answer. I get this error on my custom field and makes no difference If I am using .asApp() or .asUser():
Something went wrong
There was an error invoking the function - async()=>e.data could not be cloned.
TypeError: async()=>e.data could not be cloned.
at n.wrapValue (bootstrap.js:1:2984)
at n.wrap (bootstrap.js:1:2344)
at bootstrap.js:1:3109
at Array.map (<anonymous>)
at n.wrapArray (bootstrap.js:1:3097)
at n.wrap (bootstrap.js:1:2414)
at bootstrap.js:1:1642
at Array.map (<anonymous>)
at n.applyIgnored (bootstrap.js:1:1630)
at bootstrap.js:1:9840
I’m kinda new at Forge development and thanks for your patience
When I update my code as below, the error was gone.
const theTimeBetweenDates = async (fieldIdOrKey) => {
const res = await api
.asApp()
.requestJira(route`/rest/api/2/app/field/${fieldIdOrKey}/context/configuration`);
const config = await res.json(); //I was forgot this line of code
return config;
};
Now everything works well, thanks and regards.
Mert