Forum Discussion

sg_sripathi's avatar
sg_sripathi
New Contributor III
6 years ago
Solved

SnapLogic SDK - Accessing pipeline properties and parameters

Hi,

I am writing a custom snap in which I would like to get the pipeline name, runtime id and few predefined path parameter. I do not want to capture these as snap level properties for user to configure. Could you please let me know how to evaluate a expression like “pipe.label” without defining them as pipeline properties?

I stumbled across ExpressionUtil.compile(“pipe.uuid”); code which returns SnapLogicExpression object. But nor sure how to evaluate the expression, which seems to require additional paramters like ScopeStack and DataValueHanler.

Could you please help if there is easy way to access pipeline properties or execute a expression in custom snap?

Regars,
Sripathi

  • Hello @sg_sripathi, good question and yes this can be done.

    Inject the expression utility class:

    @Inject
    private ExpressionUtils expressionUtils;
    
    String pipeLabel;
    

    then in the configure() method:

    @Override
    public void configure(PropertyValues propertyValues)
                throws ConfigurationException {
      Document emptyDoc = documentUtility.newDocument();
      pipeLabel = expressionUtils.createExpressionProperty(
      propertyValues, true, "pipe.label").eval(emptyDoc);
    }
    

    And then you can just use the variable when writing an output document e.g.:

    Map<String, String> data = new LinkedHashMap<String, String>() {{
      put("pipeLabel", pipeLabel);
    }};
    outputViews.write(documentUtility.newDocument(data));
    

    The Mapper Snap can be used to validate whatever expression value you are trying to use in the custom Snap: