Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
CFernandes1610115000
Contributor
Contributor

Conditional update

I need to update a column 'Flag' based on values in another column completecodes

if completecodes = ['1001','1010','1011','1012','1101','1102','1104','1108','1109'] then flag=1 else flag=0

I tried using the below expression in the Flag field in the tMap component ,but got compilation errors

1010.equals(copyOfCurrMonth.responsetypecode)?1:0 

Please can you help me with this?

Labels (5)
4 Replies
Anonymous
Not applicable

To check if two strings are equal, use this expression:

"1010".equals(copyOfCurrMonth.responsetypecode)?1:0 

CFernandes1610115000
Contributor
Contributor
Author

Thank you! This expression worked.But how do I add the entire list of complete codes in the comparison condition?

Anonymous
Not applicable

I would suggest you to create a user routine and use switch...case to transform it. In Repository, click Code, followed by Routines and create a new routine. for example:

 

package routines;

 

import static java.time.temporal.TemporalAdjusters.nextOrSame;

import static java.time.temporal.TemporalAdjusters.previousOrSame;

 

/*

 * user specification: the function's comment should contain keys as follows: 1. write about the function's comment.but

 * it must be before the "{talendTypes}" key.

 * 

 * 2. {talendTypes} 's value must be talend Type, it is required . its value should be one of: String, char | Character,

 * long | Long, int | Integer, boolean | Boolean, byte | Byte, Date, double | Double, float | Float, Object, short |

 * Short

 * 

 * 3. {Category} define a category for the Function. it is required. its value is user-defined .

 * 

 * 4. {param} 's format is: {param} <type>[(<default value or closed list values>)] <name>[ : <comment>]

 * 

 * <type> 's value should be one of: string, int, list, double, object, boolean, long, char, date. <name>'s value is the

 * Function's parameter name. the {param} is optional. so if you the Function without the parameters. the {param} don't

 * added. you can have many parameters for the Function.

 * 

 * 5. {example} gives a example for the Function. it is optional.

 */

public class myRoutine {

 

  /**

   * helloExample: not return value, only print "hello" + message.

   * 

   * 

   * {talendTypes} String

   * 

   * {Category} User Defined

   * 

   * {param} string("world") input: The string need to be printed.

   * 

   * {example} helloExemple("world") # hello world !.

   */

static int returnValue=0;

   

  public static int caseDemoFunction(String completecodes ) {

     

   switch (completecodes)

    {

      case "1001":

       

       returnValue= 1;

       break;

 

      case "1002":

         returnValue= 1;

      break;

       case "1003":

         returnValue= 1;

      break;

  

      default:

       returnValue= 0;

 

     }

   return returnValue;

 

  }

   

}

 

Then, call the user routine in the expression field of column on tMap:

myRoutine.caseDemoFunction(copyOfCurrMonth.responsetypecode)

 

Hope it helps and let me know if you have any questions.

 

Regards

Shong

 

 

 

 

CFernandes1610115000
Contributor
Contributor
Author

Thank you! This worked.