Error in method invocation: Method addMessage(java.lang.String) not found in class'java.lang.String'

Hello,
I am coming to an error that I could not find a reason. Any suggestion will be helpful.

Error:
Error in method invocation: Method addMessage(java.lang.String) not found in class’java.lang.String’

Code:

<Description>
		    Rule 
		</Description>
  <Signature returnType="String">
    <Inputs>
      <Argument name="config">
        <Description>
			  The current user's locale
			</Description>
      </Argument>
      <Argument name="taskResult">
        <Description>
			  The current user's locale
			</Description>
      </Argument>
    </Inputs>
  </Signature>
  <Source>
import sailpoint.object.TaskDefinition;
import sailpoint.object.TaskResult;
import sailpoint.api.TaskManager;
String name ="1234567";
  
  
  if(name != null &amp;&amp; !name.isEmpty())
  {
    
    
    taskResult.addMessage("Identities updated ");
  }
  else
  {
    taskResult.addMessage(" No Identities ");
  }



  return  taskResult;
</Source>

The TaskResult variable is a String?

you’re doing it in a RuleTask? What you trying to do?

best!

I believe this line is causing problems - I would suggest to remove temporarly whole signature as it’s not needed really. Try to remove it and chekc if it works

1 Like

Hello @ipobeidi I am trying to run a Rule through a task but this is where it throwing error.
This is only mimicking the code.

Did you try removing the signature as @kjakubiak mentioned and tried?

Hello @iamksatish I tried @kjakubiak recommendation but system throws error.

 <Description>
    Rule 
  </Description>    
  <Inputs>
    <Argument name="config">
      <Description>
        The current user's locale
      </Description>
    </Argument>
    <Argument name="taskResult">
      <Description>
        The current user's locale
      </Description>
    </Argument>
  </Inputs>   
  <Source>

You dont need to have the taskResult as a variable. It will be on the context to be captured and updated.
Just remove the TaskResult from the input an try to add the massage.

Put back the Signature.

best!

Please try removing the Signature completely along with Inputs, you dont need this specifically.

The signature doesn’t really matter at all. It’s purely informational to let you know what is being passed into the Beanshell namespace. As @ipobeidi mentioned originally, the error indicates that the taskResult variable is of type String which doesn’t have a method for addMessage(String). This method is only applicable for a sailpoint.object.TaskResult object, in which case the taskResult variable passed into a Rule Runner task should be of that type, but it seems like you are not maybe running this rule properly via a Rule Runner task, or you are somehow re-declaring it as a String?

1 Like

Try below

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule language="beanshell" name="Vishal User">
  <Description>A rule to disable a user.</Description>
  <Signature returnType="SailPointObject">
    <Inputs>
      <Argument name="log">
        <Description>
          The log object associated with the SailPointContext.
        </Description>
      </Argument>
      <Argument name="context">
        <Description>
          A sailpoint.api.SailPointContext object that can be used to query the database if necessary.
        </Description>
      </Argument>
      <Argument name="taskResult">
        <Description>
          A sailpoint.object.TaskResult object that can be used to set messages and responses for the task result.
        </Description>
      </Argument>
    </Inputs>
    <Returns>
      <Argument name="taskSuccess" type="string">
        <Prompt>Task Result:</Prompt>
      </Argument>
    </Returns>
  </Signature>
  <Source>
        import sailpoint.object.Identity;
        import sailpoint.tools.Message;
        import org.apache.log4j.Logger;
        import sailpoint.api.ObjectUtil;
        import sailpoint.api.PersistenceManager;
        
    		String name ="1234567";
    
      	if(name != null &amp;&amp; !name.isEmpty()){   
    		            taskResult.addMessage(new Message(Message.Type.Info, "Identities updated",null));
  			}else{
    		            taskResult.addMessage(new Message(Message.Type.Info, "No Identities",null));
  			}
    return "Success";
  </Source>
</Rule>

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE TaskDefinition PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<TaskDefinition name="Vishal User" resultAction="Rename" subType="task_item_type_generic" type="Generic">
  <Attributes>
    <Map>
      <entry key="TaskDefinition.runLengthAverage" value="0"/>
      <entry key="TaskDefinition.runLengthTotal" value="0"/>
      <entry key="TaskDefinition.runs" value="0"/>
      <entry key="TaskSchedule.host"/>
      <entry key="ruleName" value="Vishal User"/>
      <entry key="taskCompletionEmailNotify" value="Disabled"/>
      <entry key="taskCompletionEmailRecipients"/>
      <entry key="taskCompletionEmailTemplate" value="Task Status"/>
    </Map>
  </Attributes>
  <Description>A task that can be used to run an arbitrary rule.</Description>
  <Parent>
    <Reference class="sailpoint.object.TaskDefinition"  name="Run Rule"/>
  </Parent>
</TaskDefinition>

@vishal_kejriwal1 Thank you very much for you solution. I will try and get back to you.

Thank you Vishal. Your code fixed my issue. I really appreciate your help.

Awesome @j1241 ! Happy Learning !!