Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8334337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:18:53+00:00 2026-06-09T03:18:53+00:00

I am a Groovy beginner These are two each calls which both do a

  • 0

I am a Groovy beginner

These are two each calls which both do a similar task but with a different property of s2PublicLifecycleInstance.

How can I write a separate function which does the following, so that I can have only method call to achive the task?

def scheduledStatusArray =[]
def publishedStatusArray =[]

s2PublicLifecycleInstance.each {
  if(it.scheduledInMyLearnStatus == "No"){
    scheduledStatusArray.add(1)
  } else if(it.scheduledInMyLearnStatus == "Yes"){
    scheduledStatusArray.add(2)
  }else{
    scheduledStatusArray.add(3)
  }
}

s2PublicLifecycleInstance.each {
  if(it.publishedOnTrainingClassesStatus == "No"){
    publishedStatusArray.add(1)
  }else if(it.publishedOnTrainingClassesStatus == "Yes"){
    publishedStatusArray.add(2)
  }else{
    publishedStatusArray.add(3)
  }
}

I want something like this:

def publishedStatusArray = functionCall(s2PublicLifecycleInstance, propertyName)

is it possible in Groovy?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:18:55+00:00Added an answer on June 9, 2026 at 3:18 am

    I agree with gasan. I can add, that
    def publishedStatusArray = functionCall(s2PublicLifecycleInstance, propertyName)
    is possible in groovy. The function:

    functionCall(def s2PublicLifecycleInstance, String propertyName){
    s2PublicLifecycleInstance."$propertyName"
    }

    will return the property you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Groovy adds each() and a number of other methods to java.lang.Object. I can't figure
Groovy adds the isAllWhitespace() method to Strings, which is great, but there doesn't seem
Groovy 1.7.5 claims to have both findResult and findAllResults . But when I try,
Using Groovy's package name convention, I can intercept Groovy method calls to a Java
I'm a beginner at groovy and I can't seem to understand this code. Can
I am using groovy/grails, and I have a ResultList in my service which I
Groovy scripts are placed in a Database entry (data type BLOB). I can read
Groovy Version: 1.8.1 JVM: 1.6.0_26 Grails Version: 2.0.0M1 visit controller which extends a abstract
As a beginner groovy developer, I am trying to understand the following lines of
DataSource.groovy appears to be evaluated before BootStrap.groovy. But, I need to setup something up

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.