Support Questions
Find answers, ask questions, and share your expertise

Issue with ScriptExecute Processor

Rising Star

HI,

I am stuck with the ScriptExecute process.I am running a small code to see how it works.

flowFile = session.get() if flowFile is not None : myAttr = flowFile.getAttribute('payload') session.transfer(flowFile, REL_SUCCESS)

But i get the attached error. It would be great if someone help me.

SJ

1 ACCEPTED SOLUTION

Accepted Solutions

Super Guru

@Sanaz Janbakhsh

Try to run the below script

flowFile = session.get() 
if flowFile is not None: 
  myAttr = flowFile.getAttribute('payload')
  session.transfer(flowFile, REL_SUCCESS)

ExecuteScript Configs:-

42671-executescript.png

In addition if you want to add an attribute,

Below script adding attribute named attr value 1 to the flowfile.

flowFile = session.get() 
if flowFile is not None: 
  myAttr = flowFile.getAttribute('payload')
  flowFile = session.putAttribute( flowFile, 'attr', '1' ) //adding attribute attr with value 1 to the flowfile
  session.transfer(flowFile, REL_SUCCESS)

View solution in original post

4 REPLIES 4

Super Guru

@Sanaz Janbakhsh

Try to run the below script

flowFile = session.get() 
if flowFile is not None: 
  myAttr = flowFile.getAttribute('payload')
  session.transfer(flowFile, REL_SUCCESS)

ExecuteScript Configs:-

42671-executescript.png

In addition if you want to add an attribute,

Below script adding attribute named attr value 1 to the flowfile.

flowFile = session.get() 
if flowFile is not None: 
  myAttr = flowFile.getAttribute('payload')
  flowFile = session.putAttribute( flowFile, 'attr', '1' ) //adding attribute attr with value 1 to the flowfile
  session.transfer(flowFile, REL_SUCCESS)

View solution in original post

Rising Star

Hi Shu,

Thanks alot for your help always. That works

I made the script to decode the payload and would like to add it to flowfile as you mentioned

flowFile = session.get() if flowFile is not None: myAttr = flowFile.getAttribute('payload') out=base64.b64decode(myAttr) out1=base64.b16encode(out) flowFile = session.putAttribute( flowFile, 'attr', 'out1' ) session.transfer(flowFile, REL_SUCCESS)

Got the attached error. Any thoughts please.1.png

Super Guru

@Sanaz Janbakhsh,

Use the below script to add the encoded payload attribute to the flow file.

Script:-

import base64  
flowFile = session.get() 
if flowFile is not None: 
  myAttr = flowFile.getAttribute('payload') 
  out=base64.b64decode(myAttr) 
  out1=base64.b16encode(out) 
  flowFile = session.putAttribute( flowFile, 'attr', out1)
  session.transfer(flowFile, REL_SUCCESS)

diff between 'out1',out1

flowFile = session.putAttribute( flowFile, 'attr', 'out1') //script adds attribute attr value as out1(because out1 is in single quotes). if you want to add the out1 actual encoded value we need to use out1 without single quotes.

Here is an example i tried:-

i am having payload attribute value as asdf.

Python shell output:-

>>> import base64
>>> out=base64.b64decode('asdf')
>>> out1=base64.b16encode(out)
>>> print out1
6AC75F

NiFi Script:-

42673-executescript.png

Output:-

42674-executescript-op.png

As you can see above payload attribute value is asdf and script attr value is 6AC75F, Python shell output and script outputs are matching.

Rising Star

Thanks shu, really helpful.