My Radio Button(custom Field) is giving Object instead of the value

Rao Tripuraneni May 12, 2024

Hello everyone - i have a piece of code on Behaviours On Load event to make 2 fields Read Only and to do that i am getting a custom field value.i added logging to see what values are coming to compare with.But in the logs i see the following line [Object Object].

 

please advise.

Here is the code snippet:

const fixVersions = getFieldById("fixVersions")
const group = "PM";
const locked = getFieldById("customfield_11185");
const lockedvalue = getFieldById("customfield_11185").getValue()
const myvalue = "The Value of Flag is"
logger.info(myvalue + lockedvalue)

fixVersions.setReadOnly(true)
locked.setReadOnly(true)

const user = await makeRequest("/rest/api/2/myself");
if (user) {
    const { accountId } = user.body;
    logger.info("account : " + accountId)
    const userGroups = await makeRequest ("/rest/api/2/user/groups?accountId=" + accountId);
   if (userGroups) {
        const groupNames = userGroups.body.map(({ name }) => name);
        logger.info("groupname : " + groupNames)
        if (groupNames.includes(group)) {
            fixVersions.setReadOnly(false)
            locked.setReadOnly(false)
        }
    }
}
Behaviour Logs-
Timestamp: 2024-05-12T12:46:06.750Z
CorrelationId: aeb129ce-2e8e-4726-b5d0-17745482c0df
Field UUID: 4bab493d-aef2-4b01-b30e-d678126f037c
Field Name: customfield_11185,fixVersions
Event: On Load
Message: The Value of Flag is[object Object]
Level: info
View: Issue view

1 answer

1 accepted

0 votes
Answer accepted
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 12, 2024

Hi @Rao Tripuraneni 

It seems that the lockedvalue is an object and not a simple value like a string or number. JavaScript uses the toString() method to convert objects to strings for concatenation, and the default toString() method for an object returns [object Object]. 

You need to ensure you are accessing the relevant property of the object that holds the actual value you want to log. To see the structure of the object you can just try to log the lockedvalue.

 

logger.info("Locked value object:", lockedvalue);

 Then you can see the structure and log whichever part is convenient.

I hope it helps!

Tuncay

Rao Tripuraneni May 13, 2024

Hello Tuncay- Thanks for the response.

 

i made a change in the script to get the value by updating the line like below and it started working.

 

Before-

 

const lockedvalue = getFieldById("customfield_11185").getValue()

 

After-

const lockedvalue = getFieldById("customfield_11185").getValue().value

 

 

Appreciate your help!!

 

Thank You

Rao

Like Tuncay Senturk likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events