Dear Community User! We are updating our platform to a new system.
Read more: Important information on the platform change.

cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

Recipe name

Recipe name

David08
Long-established Member

Is there a system variable or an option to read the name of the loaded/selected recipe and write it to a PLC variable?

Thanks in advance.

7 REPLIES 7

webiq-sk
Frequent Contributor

No, because WebIQ does not know about any recipe status - it simply applies all of the values in the recipe to the defined items - nothing more.

You can however simply add an item to your recipe that contains a specific name you want to display as the "currently running recipe"

David08
Long-established Member

Hello webiq-sk,

That's what I had thought, but the customer doesn't like it very much because you have to make sure that you write the same name in both places to avoid confusion.

Thanks for the reply.

Sgilk
Frequent Contributor

You can also use the Visuals API to access recipe data, including the name. Here is an example of printing out all stored recipes.

 

(function () {

    /**
     * replace module name with a custom name for the local-script.
     *
     * All local-script should be attached to the "custom.ls" package.
     * If more than one script is required for an application, a common root package
     * should be created (e.g. "custom.ls.customerName.*").
     */

    var MODULE_NAME = "getRecipeName",
        ENABLE_LOGGING = false,
        RECORD_LOG = false,
        logger = shmi.requires("visuals.tools.logging").createLogger(MODULE_NAME, ENABLE_LOGGING, RECORD_LOG),
        fLog = logger.fLog,
        log = logger.log,
        module = shmi.pkg( MODULE_NAME );

    // MODULE CODE - START

    /* private variables */

    /* private functions */
    function listTemplatesCallback(response,err){
        if(!err){
            for(template in response.templates){
                rm.listRecipes(response.templates[template].id,{},listRecipesCallback);
            }
        } else {
            console.log("Error getting templates: " + err);
        }
    };

    function listRecipesCallback(response,err){
        if(!err){
            for(recipe in response.recipes){
                console.log(response.recipes[recipe].name);
            }
        } else {
            console.log("Error getting recipes: " + err);
        }
    };

    /**
     * Implements local-script run function.
     *
     * This function will be called each time a local-script will be enabled.
     *
     * @param {LocalScript} self instance reference of local-script control
     */
    module.run = function (self) {
        // Get recipe manager
        rm = shmi.visuals.session.RecipeManager;
        // Retrieve all templates and corresponding recipes
        rm.listTemplates({}, listTemplatesCallback);

        //Place your Code here

        /* called when this local-script is disabled */
        self.onDisable = function () {
            self.run = false; /* from original .onDisable function of LocalScript control */
        };
    };


    // MODULE CODE - END

    fLog("module loaded");
})();

 

David08
Long-established Member

Hello Sgilk,

Your script works, but is there any option to be able to read the index or row number selected in the table and use your Script or in UI-Action with the selected pointer.
I am interested in reading the picture data.

David08_0-1730129673295.png

Thanks.

Sgilk
Frequent Contributor

@David08 ,

There are not configurable UI actions for the Recipe List widget. You will have to query for the element in Javascript and programatically add event handlers if you want to go that route.

David08
Long-established Member

Thanks Sgilk for the reply,

I don't have the necessary knowledge in JavaScript with event handlers to do the function. Only the client asks me to write in a PLC variable of type String the name of the recipe applied when applying the recipe.

Sgilk
Frequent Contributor

@David08 ,

I think by far the easiest solution in this case is the accepted answer from @webiq-sk

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist