Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Verify last instance of a textfield is not null

Avatar

Level 9

I have a repeating subform that includes a textfield for the user to enter their name. When the user clicks a custom email button to send the form I want to first verify if the last instance of that field was populated (not null). I don't care about the previous instances only the last instance. The custom email button is pushed down below each instance of the subform so it is always just below the last instance of the repeating subform. Is there a way to refer to the last instance of a subform field when i don't know how many instances will be created?

Thanks

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Hi DKinsley,

I think the following steps and code will solve your problem.


1) In order to know the last instance, you need to find the count of instances available. This can be achieved through the following code"

var totalRowInstances = xfa.resolveNode("form.Name.txtName").instanceManager.count;

2) To access the last index value,

     var lastIndex = totalRowInstances-1;

//[Since the index always starts with 0]

     var lastIndexNameCheck = xfa.resolveNode("form.Name["+lastIndex+"]").txtName.rawValue;

     if(lastIndexNameCheck != null)
     {
           //do something
     }
     else
     {
           //do something
      }

Please Note : Here, form - refers to root node, Name - refers to subform, txtName - refers to name of the text field.

Please let me know if this helped.

Thanks,
VJ

View solution in original post

2 Replies

Avatar

Correct answer by
Former Community Member

Hi DKinsley,

I think the following steps and code will solve your problem.


1) In order to know the last instance, you need to find the count of instances available. This can be achieved through the following code"

var totalRowInstances = xfa.resolveNode("form.Name.txtName").instanceManager.count;

2) To access the last index value,

     var lastIndex = totalRowInstances-1;

//[Since the index always starts with 0]

     var lastIndexNameCheck = xfa.resolveNode("form.Name["+lastIndex+"]").txtName.rawValue;

     if(lastIndexNameCheck != null)
     {
           //do something
     }
     else
     {
           //do something
      }

Please Note : Here, form - refers to root node, Name - refers to subform, txtName - refers to name of the text field.

Please let me know if this helped.

Thanks,
VJ

Avatar

Level 9

This appears to work well - thanks so much.

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] ----