Topic
11 replies Latest Post - ‏2012-12-21T01:26:41Z by SystemAdmin
SystemAdmin
SystemAdmin
648 Posts
ACCEPTED ANSWER

Pinned topic how to refresh attribute value after the value rule changed?

‏2012-12-17T03:05:35Z |
In a catalog, we have almost 30 thousand items. in the spec, we have 2 attributes, one is Name, another is URL. There was a value rule for URL is that if the Name is not empty, then the URL would be "http://xxxxxx.com/xx/" + Name, otherwise, returns empty.
Now I need to change the value rule, update the "http://xxxxxx.com/xx/" to "http://yyyyyy.com/yy/". But after I updated the value rule, the values of the URLs in all items do not change.
I guess I need a way to refresh the vales, and I got a way is that save the items(changes nothing), but it will also modify the update date and user information for the items.
My question is, do we have a easier way to refresh the values? Thank you!
Updated on 2012-12-21T01:26:41Z at 2012-12-21T01:26:41Z by SystemAdmin
  • babinag
    babinag
    91 Posts
    ACCEPTED ANSWER

    Re: how to refresh attribute value after the value rule changed?

    ‏2012-12-17T04:36:54Z  in response to SystemAdmin
    Hi DeanJi.
    I think you need raw import without processing any validations/rules.

    You may achieve this from scripting or javaapi.
    From javaapi, before start import, you need to disable all processing options:
    
    catalogToImport.getProcessingOptions().setAllProcessingOptions(
    
    false);
    

    From scripting, check function disableContainerProcessingOptions
    • SystemAdmin
      SystemAdmin
      648 Posts
      ACCEPTED ANSWER

      Re: how to refresh attribute value after the value rule changed?

      ‏2012-12-17T05:13:32Z  in response to babinag
      Thank you for response my question.
      I updated the value rule from UI in specs console.
      May I know what's the meaning of raw import?
      • babinag
        babinag
        91 Posts
        ACCEPTED ANSWER

        Re: how to refresh attribute value after the value rule changed?

        ‏2012-12-17T05:28:23Z  in response to SystemAdmin
        The meaning of raw, is that modifying and then save operation during import do not involve processing of value rules, post/pre scripts, validation rules.
        • SystemAdmin
          SystemAdmin
          648 Posts
          ACCEPTED ANSWER

          Re: how to refresh attribute value after the value rule changed?

          ‏2012-12-17T05:44:10Z  in response to babinag
          Thank you for the explaining.
          I am not very sure about this. When I updated the value rule in UI, there was no job running. After I updated the value rule, the value of the attribute does not changed as expected.
          • babinag
            babinag
            91 Posts
            ACCEPTED ANSWER

            Re: how to refresh attribute value after the value rule changed?

            ‏2012-12-17T05:59:42Z  in response to SystemAdmin
            DeanJi, the fact, that you have changed value rule at spec node will impact only on newly added items, or to items that been saved after modification done.

            The way you can apply modified value rule - save all items. You can do it manually or by means of report, import, export jobs, by sandbox script. Either way except import, when you save item, all processing operations like validations, postprocess, postsave, valuerule, and other, will apply to that item. That means, that "...but it will also modify the update date and user information..." occurs.
            If you will use import job, you can avoid unwanted modifications by disabling processing options.
            You need to implement new value rule logic in import, and use it to change values at each item without side effects.
            • SystemAdmin
              SystemAdmin
              648 Posts
              ACCEPTED ANSWER

              Re: how to refresh attribute value after the value rule changed?

              ‏2012-12-17T08:46:23Z  in response to babinag
              I would try to create an import job to save all items, looks like it's the only way. Thank you!
              • KaranBal
                KaranBal
                108 Posts
                ACCEPTED ANSWER

                Re: how to refresh attribute value after the value rule changed?

                ‏2012-12-17T21:33:15Z  in response to SystemAdmin
                If you want to save all the items in a catalog, then you can use the following script from scripting Sandbox:

                var ctg = getCtgByName("Catalog_Name");
                var items = ctg.getItemSetForCatalog();
                var theItem;
                forEachItemSetElement(items,theItem) {
                // out.writeln(getCtgItemPrimaryKey());
                theItem.saveCtgItem();
                }
                But this may lead to an error for items which are checked out to a collaboration area and so java code within the try catch block may be a better option.
                • SystemAdmin
                  SystemAdmin
                  648 Posts
                  ACCEPTED ANSWER

                  Re: how to refresh attribute value after the value rule changed?

                  ‏2012-12-18T11:53:05Z  in response to KaranBal
                  Hi Karan:) , I tried to create an import job via java or script, I assume it would work.
                  But I've got error when saving items, might be data corruption, already raised a ticket for help;)
  • SystemAdmin
    SystemAdmin
    648 Posts
    ACCEPTED ANSWER

    Re: how to refresh attribute value after the value rule changed?

    ‏2012-12-20T14:03:25Z  in response to SystemAdmin
    Hi,
    I still find it strange that nothing happens after changing the valuerule. Might be that the new code is not working because of some caching issues. I had that with one customer and the changed scripts would only be applied after a restart of the PIM server. The cause was that the multi-cast address could not be reached and therefor the old script stayed in memory (or something like that). after enabling multi-cast on the server it worked again. Just try to ping the multi-cast address that is put in the config files and that is the first check.

    I think that mass item update script should really work or otherwise take out the value rule script and use a postprocessing script to set the value of the item and then save all the items again. Using this postprocessing script you can define what fields you need updated and take of the value rule of the update date and user information. This way you can implement all the value rules in the post (or pre) processing script and easily take out or add new value rules

    Regards,
    Han
    • SystemAdmin
      SystemAdmin
      648 Posts
      ACCEPTED ANSWER

      Re: how to refresh attribute value after the value rule changed?

      ‏2012-12-20T14:12:34Z  in response to SystemAdmin
      Or put this in an import script, that way you can use the processingOptions: (and I believe this will work)
      var ctg = getCtgByName("Catalog_Name");
      processingOptions.add("ALL");
      ctg.disableContainerProcessingOptions(processingOptions);//this disables all pre and post processing options and also value rules

      var item = null;

      forEachCtgItem("Catalog_Name", item){
      var strName = item.getEntryAttrib("SPEC/Name");
      item.setEntryAttrib("SPEC/Url", "http://yyyyyy.com/yy/" + strName);
      item.saveCtgItem();
      }
      • SystemAdmin
        SystemAdmin
        648 Posts
        ACCEPTED ANSWER

        Re: how to refresh attribute value after the value rule changed?

        ‏2012-12-21T01:26:41Z  in response to SystemAdmin
        Hi Han, Thank you for the script details. I had created an import job to do so days ago, but I got data corruption in the catalog, need solve the corruption first. after that, I will run the job again to see if it works.