Does kibana watcher action supports painless script?

Hi Experts,

Is it possible to write painless script mentioned below under kibana watcher action? I checked foreach example mentioned in elastic.co documentation; however, I am not sure if it supports inner loops.

script

"script": {
      "source": """
     if (ctx.payload.aggregations?.jobstatusid != null) {
  for(int i = 0; i < ctx.payload.aggregations.jobstatusid.buckets.length; i++)
      {    
		def id = ctx.payload.aggregations.jobstatusid.buckets[i];
		if (id?.ErrorMsg != null) 
			{
				for(int j = 0; j < id.ErrorMsg.buckets.length; j++)
					{
						def msg = id.ErrorMsg.buckets[j];
						if (msg?.jobname != null) 						
						{
							for(int q = 0; q < msg.jobname.buckets.length; q++)
							{
							 def name = msg.jobname.buckets[q];
							 if (name?.emailids != null)							 
							 {
							    for(int t = 0; t < msg.jobname.buckets.length; t++)
								 {
								    def email = name.jobname.buckets[t];	
								     	
							 }
							}
        }
      }
    }
  }
}
}""",
      "lang": "painless"
    }

Thanks in advance!
Nivedita