Skip to main content


Hi when using the Filter in the expression builder is it possible to search for a sub-string in a string? The filter operation 'in' seems to match only on the entire string?


Hi
@Mark Rodman
! How are you? It's not possible to search for a sub-string in a String by the expression builder but you can use the Power up "Jinja - TemplateEngine", this integration provides the ability to render templates so I'll recommend you to use it. Please let me know if you have any further questions



View files in slack



Just came here to say +100 to the Jinja Template Engine. I use it to customize all of my outputs from emails to ServiceNow ticket comments (complete with html coding! Try it in your SN instance with

code:
 
)



I'm attempting to do the following:


Search for a substring in a results set, then build the input to another action.


To be honest I've simply build a custom action which performs concatenation and string splitting which does the job.


Easier



that's probably what i would suggest if you didn't want to use jinja. You could use jinja to take in the original result set and return the desired string. Then have the next action work off the jinja result



# -----------------------------------------------------------------------------------


# Mark Rodman


# Bumble Tools


# -----------------------------------------------------------------------------------


# Description


# Quick and dirty solution to concat 3 strings together.


# Need to solve a specific solution, but might come in handy at some point!


# ----------------------------------------------------------------------------------


# Notes


#


#. Add_White_Space (boolean) is used to add white space between the 3 strings ie.


# True = "startStr middleStr endStr"


#. False = "startStrmiddleStrendStr"


#. Siemplify appears to remove whitespace during playbook execution, but not during


#. IDE Testing, the boolean provides flexibility regardess.


#


#. Now supports order_list, csv list of strings. If used, the start,middle,end are ignored.


# ----------------------------------------------------------------------------------


from SiemplifyAction import SiemplifyAction


from SiemplifyUtils import unix_now, convert_unixtime_to_datetime, output_handler


from ScriptResult import EXECUTION_STATE_COMPLETED, EXECUTION_STATE_FAILED,EXECUTION_STATE_TIMEDOUT





INTEGRATION_NAME = u"BumbleTools"


SCRIPT_NAME = u"ConcatStrings"





@output_handler


def main():


siemplify = SiemplifyAction()


siemplify.script_name = SCRIPT_NAME


result_value = False # Set a simple result value, used for playbook if\\else and placeholders.





siemplify.LOGGER.info("================= Main - Param Init =================")


startStr = siemplify.extract_action_param(param_name="StartString", is_mandatory=False, print_value=True)


middleStr = siemplify.extract_action_param(param_name="MiddleString", is_mandatory=False, print_value=True)


endStr = siemplify.extract_action_param(param_name="EndString", is_mandatory=False, print_value=True)





orderedList = siemplify.extract_action_param(param_name="ordered_list", is_mandatory=False, print_value=True)





addWhiteSpace = siemplify.extract_action_param(param_name="Add_white_spaces", is_mandatory=False, print_value=True)





output_message = "Starting {}, {}\\n".format(INTEGRATION_NAME, SCRIPT_NAME) # human readable message, showed in UI as the action result





try:


finalStr = ""





if orderedList:


# Use the csv list (still a string though!)


# Will ignore the start middle end strings


output_message += "CSV list being used {}".format(orderedList)


output_message += ""


realList = orderedList.split(',')





if addWhiteSpace.lower() == 'true':


finalStr = ' '.join(realList)





else:


output_message += "not whitespace"


finalStr = ''.join(realList)


output_message += finalStr


else:


if startStr:


output_message += "---Start string: {}\\n".format(startStr)


else:


startStr = ""





if middleStr:


output_message += "---Middle string: {}\\n".format(middleStr)


else:


middleStr = ""





if endStr:


output_message += "---End string: {}\\n".format(endStr)


else:


endStr = ""





if addWhiteSpace.lower() == 'true':


finalStr = startStr + " " + middleStr + " " + endStr


else:


finalStr = startStr + middleStr + endStr





output_message += "Resultant string: {}".format(finalStr)





result_value = finalStr


status = EXECUTION_STATE_COMPLETED # used to flag back to siemplify system, the action final status





except Exception as e:


siemplify.LOGGER.error("General error performing action {}".format(SCRIPT_NAME))


siemplify.LOGGER.exception(e)


status = EXECUTION_STATE_FAILED


result_value = False


output_message += "\\n unknown failure"





siemplify.LOGGER.info("\\n status: {}\\n result_value: {}\\n output_message: {}".format(status,result_value, output_message))


siemplify.end(output_message, result_value, status)





if __name__ == "__main__":


main()



if you are interested the code is above



the middle string is a known response, the start and end are static, or you can use the csv ordered list



its rough and ready but works!


Reply