This is a public Forum  publicRSS

Topic

    Cristian Nieva
    after changing a field value, how to set another field value...Answered
    Topic posted January 24, 2017 by Cristian NievaJourneyer 
    153 Views, 12 Comments
    Title:
    after changing a field value, how to set another field value that depends on the first value
    Content:

    Hi All,

    In a custom console workspace, I'm trying to set a second field value, that depends on the first field value.

    For example, when I select an employee from the list, I want to auto populate the manager of it.

    Is it possible to do a query to get the manager in a rule? or is there any other way to do it?

    Thanks,

    Cristian

    Best Answer

    Anurag Mittal

    The cleaner way of doing this is through Add-in, you get greater control and flexibility.

    JavaScript API is another way of doing it,  but you won't be able to run connect PHP API directly from JavaScript either you to call Ajax or you have store employer-manager relationship in PHP array on script load.

    Answer

     

    • Narendra Muttineni

      Use the Workspace Rules to achieve this functionality.

      Thanks,

      Narendra

    • Cristian Nieva

      Hi Narendra,

      I tried to use the rules, but on them I need to hardcode the values, and I'm looking for a way to do it dynamically, otherwise I'll need to generate multiples rules, one for each employee name/ID, and it will be hard to maintain.

      Thanks,

      Cristian

    • Pramod Vasudeva Murthy

      You can use Javascript API and set it accordingly, advantage here is there will be only one script in workspace. No need of multiple rules.

      Use custom script for connect PHP API if needed.

      - VIP

    • Anurag Mittal

      The cleaner way of doing this is through Add-in, you get greater control and flexibility.

      JavaScript API is another way of doing it,  but you won't be able to run connect PHP API directly from JavaScript either you to call Ajax or you have store employer-manager relationship in PHP array on script load.

    • Cristian Nieva

      Thanks all for your help, I'll go with the .Net add-in.

    • Danette Beal

      Thanks for the update Cristian!

      Glad the Community could help.

    • Vijaya

      HI Cristian,

      Can I get the sample code of this requirement.

      Thanks in advance

    • Cristian Nieva

      Hi Suryasree,

      I created a rule that fires a named event when the field value change, then in the addin I created a IWorkspaceComponent2 class where in the RuleActionInvoked function I checked for the action name.

      something like this:

      using System;
      using System.AddIn;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows.Forms;
      using RightNow.AddIns.AddInViews;
      using RightNow.AddIns.Common;
      
      namespace AddInProject
      {
          public class MyAddin : Panel, IWorkspaceComponent2
          {
              public void RuleActionInvoked(string actionName)
              {
                  if (actionName != "myNamedEvent") return;
      // do something here
              }
          }
      }
      

      Regards,

      Cristian

    • Vijaya

      Hi I created a rule like when field changes to specific value then execute my addin(gave actionname). control is coming to ruleactioninvoke. My question is how to populated value in other field? Is need to initialise the object and set the value to the generic field??please give me a sample.

      Field 1 -checkbox, Field2 - textbox

      On checkbox checks, current loggedin user name has to populate in field 2(so I need to return loggedin user name and set to field 2 from addin when rule invokes)

      is it possible to set the value dynamically???

      Thanks in advance

    • Cristian Nieva

      Hi Suryasree,

      Once that you are in the addin, you should be able to do what ever you want with the values.

      This is an example code for setting a value to a custom attribute     

      IIncident incidentRecord = _recContext.GetWorkspaceRecord(RightNow.AddIns.Common.WorkspaceRecordType.Incident) as IIncident ;
      IList<ICustomAttribute> ica = incidentRecord.CustomAttributes;
      ICustomAttribute ca = ica.First(c => c.GenericField.Name == "CO$myfield");
      ca.GenericField.DataValue.Value = true;
      
      _recContext.RefreshWorkspace();
      

      Thanks,

      Cristian

    • Vijaya

      Hi Cristian,

      I am working with asset object. So Directly I am not getting the Asset workaspace record. For this I did like below

      var recordcontext = _recordContext.GetWorkspaceRecord(_recordContext.WorkspaceTypeName);
                  int assetid = (int)recordcontext.GetType().GetProperty("ID").GetValue(recordcontext);

      using ROQL: I am getting all customattributes.

       #region ROQL
                  ClientInfoHeader clientInfoHeader = new ClientInfoHeader();
                  clientInfoHeader.AppID = "Retrieve Data";
                  string Querystring = "SELECT Asset FROM Asset WHERE Asset.ID = " + assetid;
                  Asset asset = new Asset();
                  asset.CustomFields = new GenericObject();
                  asset.CustomFields.GenericFields = new GenericField[] { };
                  RNObject[] template = new RNObject[] { asset };
                  QueryResultData[] queryResults = _client.QueryObjects(clientInfoHeader, Querystring, template, 1000);
                  RNObject[] assets = queryResults[0].RNObjectsResult;
                  if (assets.Length > 0)
                  {
                      Asset asset1 = (Asset)assets[0];
                      GenericField[] genf = ((PopulateLogindetinAsset.ServiceReference1.GenericObject)asset1.CustomFields.GenericFields[0].DataValue.Items[0]).GenericFields;
                      if (genf.Count() > 0)
                      {
                          GenericField genField = genf.First(x => x.name == "RecommendedBy");
                          if (genField.DataValue == null)
                          {
                              DataValue dv = new DataValue();
                              dv.Items = new[] { Login };
                              genField.DataValue = dv;                      
                          }
                      }
                  }
                  #endregion
                  _recordContext.RefreshWorkspace();

       

      So we are not getting CustomAttributes from RecordContext. So whatever we updating in the CustomAttributes from ROQL are not reflecting in the RecordContext. so the values are not setting in the fields. Please check this once.

      ​ThanksInAdvance.

    • Pramod Vasudeva Murthy

      Please close this thread and create a new thread as this has an answer selected for this post. Link this thread to your new post as a reference.

      ~VIP