Friday, May 26, 2017

Some Handy Moca Commands

Overview

In this blog post I am listing some handy MOCA commands that can help when performing adhoc support tasks on a RedPrairie server.
Command Description Sample Call Sample Use Case
Manage data via in memory tables
File System
remove file Remove a file on the file system remove file where filnam = 'xxxx' You can remove a file on the file system
sl_cat file get contents of a file in a single string sl_cat file where filename = @@DCSDIR || '.../move_inventory.mcmd' You can read a file in one string and then you could search for text within tha file
write output file write file on the file system write output file where path = @@LESDIR || '/log' and filnam = 'temp.log' and data = 'test' You can write a file on the file system
find file Look for files on the file system /* * This simple snippet traverses * all custom code and lists * all source code files */ find file where pathname = @@LESDIR || '/src/cmdsrc/*' | { if ( @type = 'D' ) find file where pathname = @pathname || '/*.m*' } You can query all commands for a certain text without going at the file system
Command Repository
list active commands This will list all active commands on the server without need of going to the file system. It will return business logic as well list active commands where command = "list carrier details" You can query all commands for a certain text without going at the file system
list active command arguments This will list all command arguments for a command list active command arguments where command = "move inventory" You can query all command arguments for a certain text without going at the file system
list active triggers This will list all command triggers for a command list active triggers where command = "move inventory" You can query all command triggers for a certain text without going at the file system
Database. RedPrairie supports multiple databases. These commands make it easy to query data dictionary without worrying about specific database being used
sl_get db_info Get important information about the database we are connected to sl_get db_info get basic information like database type, name, instance, schema, version, etc.
dbtype Function to get database type, i.e. ORACLE or SQLSERVER publish data where x = dbtype() Useful if you every have to write database specific code
list user tables Get all the tables in the database /* * Return all authentication * tables */ list user tables where table_name like 'LES%ATH%' Useful to do adhoc database operations
list table columns Get all the columns for a table list table columns where table_name = 'les_usr_ath' Useful to do see columns of a table
list tables with column Get all the tables in data dictionary that have a certain column list tables with column where column_name = 'usr_id' To find affect of changing value of a column or other adhoc support tasks
list table indexes Get all indexes for a table list table indexes where table_name = 'invlod' To see indexes for a table and then columns within the index in easy to read format as a coma-separated list
Groovy Groovy Groovy
And best of all is Groovy - you can do almost anything you can imagine. Call web services, perform complex string operations etc. etc. etc. With groovy available there is hardly ever a need to write components in C or Java

22 comments:

  1. Thanks Saad, keep 'em coming.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. Hello Saad, I have a few questions about writing Java and C components:

    1. After code is developed and files are put in desired directories, how would one go about compiling it?
    2. Before implementing a C or Java function, what is the best way to go about testing it?
    3. Which editors/IDEs do you recommend for above?

    Thank you very much for taking the time to write to this blog; I am learning a lot! I hope to hear from you.

    ReplyDelete
    Replies
    1. ant can be used for all java code. You will see a build.xml file in $LESDIR. C code can be compiled using make and standard compilers.

      But if you are doing server side components - there will hardly be a need to do java or C - groovy pretty much provides you all you need.

      Delete
  4. Hello Saad,

    I have a question regarding moca command "process inventory adjustment".
    We have a requirement to mass upload all the available inventory in the warehouse.

    Can you please provide any suggestion on what can be the method for mass uploading the inventory?

    I am totally confused if the process inventory adjustment command can somehow be used for bulk uploads or if there is some other way to do that.

    Thank you.

    ReplyDelete
  5. Hi Varuni,
    You can do that by running a command like this:
    publish data where prtnum ='ITEM NUMBER' and lotnum = 'BATCH INFO' and stoloc = 'STORAGE_LOCATION' and untqty = '4' and expire_dte = '20181101000000' and mandte = '20180430000000' and usr_id = 'USER_ID' and adj_ref1 = 'REFERENCE' and invsts = 'INVENTORY_STATS'.

    I've got an excel that creates these commands in bulk for me, you just need to paste all the information needed in some columns.

    I hope this helps.

    ReplyDelete
    Replies
    1. Hello Chrille,

      Thank you. The issue I am facing is that process inventory adjustment has a whereclause create inventory.

      This is where I am stuck in creating excel.

      Can you please suggest anything on that.

      Thank you.

      Delete
    2. Hi,
      Inventory adjustment is just that, adjustment of inventory already in stock. WHat is it exactly that you want to achieve?

      Delete
    3. I want to do a mass upload of inventory.

      Delete
  6. Hello Chrille,
    I am new to MOCA, could you please tell me what is the use of "publish" command. is it like update or anything else?

    Thanks.

    ReplyDelete
    Replies
    1. MOCA execution context is a stack. Much like use of |s in Windows or Unix OS. Output of one command becomes input of the next. So for example you do "dir" its output is list of files in a directory. The next command can work on this "output" as "input", e.g. a copy command or delete command.

      "publish data" is a simple command whose only purpose is to simply publish what is passed in. So it serves as a tool to manipulate the execution context.

      In SQL world on Oracle we sometimes to select from dual. or in SQLsever we do select without a table - this is in some ways similar to that idea. Or if working in shells; we can use echo to enter data to a stack stream.

      Delete
  7. what does the sprintf MOCA function do?Can you give some example about sprintf function and other complex MOCA function?

    ReplyDelete
  8. How do i run 2 of the same commands at the same time

    ReplyDelete
  9. I am very new to MOCA and I am trying to capture user input via a workflow with a move inventory trigger. Is there a MOCA command that allow you to accept user entry beyond the Y/N workflow response?

    what does @@ mean

    ReplyDelete
  10. Hello Saad,

    is there any detail document on mtf_server_config.properties
    was mainly looking for more details on below configuration

    terminal.floodprotection
    terminal.maxcon
    terminal.maxqueued

    ReplyDelete
  11. HI Sir I am totally new for MOCA. Can you please, suggest any link or PDF Tutorial with command set for beginners

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. I am working on a new client https://github.com/IkeRolfe/JdaTools/releases
    give it a try and drop some feedback.
    This a VERY early version.

    ReplyDelete
  14. All thanks to Mr Anderson for helping with my profits and making my fifth withdrawal possible. I'm here to share an amazing life changing opportunity with you. its called Bitcoin / Forex trading options. it is a highly lucrative business which can earn you as much as $2,570 in a week from an initial investment of just $200. I am living proof of this great business opportunity. If anyone is interested in trading on bitcoin or any cryptocurrency and want a successful trade without losing notify Mr Anderson now.Whatsapp: (+447883246472 )
    Email: tdameritrade077@gmail.com

    ReplyDelete