Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

CustomField doesn't seem to be set

Avatar

Former Community Member
Good morning,



I would like to use CustomField to identify the connected
members. The CustomField doesn't seem to work. I've added some
trace to check:



if (!cSession.userManager.isCustomFieldDefined("memberID")){

cSession.userManager.registerCustomUserField("memberID");

}

cSession.userManager.setCustomUserField(cSession.userManager.myUserID,
"memberID", myMemberID);

status.text=status.text+" \n setting memberID "+myMemberID;

status.text=status.text+" \n memberID set to
"+cSession.userManager.getUserDescriptor(cSession.userManager.myUserID).customFields.memberID;



I get the following content in the status field:

setting memberID 123

memberID set to undefined



Am I doing something wrong?



Regards,



Axel
1 Accepted Solution

Avatar

Correct answer by
Former Community Member
Hi,



There are some things I would point out and also attach a
code I ran solving your problem.

a) After you set the customField, you need to wait till its
actually set, you need to wait till you receive the
CUSTOM_FIELD_CHANGE event from usermanager ( see my attached code).

b) The way you access a customField is
customFilelds['fieldName'] and not customFields.fieldName



Lastly ,as an added information in the next drop which is
coming in few weeks, we have added ways where you get an event once
you have registered your customFileld so that you wait for it
before setting your customFiled ,and also you would be able to
delete your customField. And you can also do both register and
delete from the dev console.



Here is the complete attached code for your problem

View solution in original post

5 Replies

Avatar

Correct answer by
Former Community Member
Hi,



There are some things I would point out and also attach a
code I ran solving your problem.

a) After you set the customField, you need to wait till its
actually set, you need to wait till you receive the
CUSTOM_FIELD_CHANGE event from usermanager ( see my attached code).

b) The way you access a customField is
customFilelds['fieldName'] and not customFields.fieldName



Lastly ,as an added information in the next drop which is
coming in few weeks, we have added ways where you get an event once
you have registered your customFileld so that you wait for it
before setting your customFiled ,and also you would be able to
delete your customField. And you can also do both register and
delete from the dev console.



Here is the complete attached code for your problem

Avatar

Former Community Member
Hi Hironmay,



It works perfectly. Did I miss something in the
documentation, because I didn't see that it was asynchronous?



Cheers,



Axe

Avatar

Level 3

Hi Hironmay

Your tips are very helpful.

Is it possible to access the attached code that you have refered to in this post?

Thanks

Avatar

Former Community Member

Hi,

I just made up a code at that point of time and didn't store it. But there is an example on using Custom Fields in the sampleApps folder of the SDK. At the time of that post, the example was not there and so I had to attach some sample. You will find every details inside the example now and most of my attached code is also there inside that example.

Hope this helps.

Thanks

Regards

Hironmay Basu

Avatar

Level 3

Thanks - I wish I had used the sample apps earlier - really useful.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----