Friday, March 21, 2014

Script to Set the Global Info (FND_GLOBAL.APPS_INITIALIZE)

PROCEDURE set_global_info(
   p_responsibility_id      IN             NUMBER := fnd_api.g_miss_num
 , p_user_id                IN             NUMBER := fnd_api.g_miss_num
 , p_resp_appl_id           IN             NUMBER := 275
 , p_msg_count              OUT            NUMBER
 , p_msg_data               OUT            VARCHAR2
 , p_return_status          OUT            VARCHAR2
)
IS
   l_api_name               CONSTANT VARCHAR2(30) := 'Set_Global_Info';
   l_value_conversion_error BOOLEAN := FALSE;
   l_return_status          VARCHAR2(1);
   l_dummy                  VARCHAR2(1);
   l_temp_num               NUMBER;

   CURSOR l_resp_csr
   IS
      SELECT 'x'
        FROM fnd_responsibility
       WHERE responsibility_id = p_responsibility_id
         AND application_id = p_resp_appl_id;

   CURSOR l_user_csr
   IS
      SELECT 'x'
        FROM fnd_user
       WHERE user_id = p_user_id;

   l_resp_csr_rec                                    l_resp_csr%ROWTYPE;
BEGIN
   IF    p_responsibility_id IS NULL
      OR p_responsibility_id = fnd_api.g_miss_num
   THEN
      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_error)
      THEN
         -- Define the Custom message as XX_RESP_ID_REQD with
         -- Description as "A valid responsibility is required."
         fnd_message.set_name('XX_APPL_NAME', 'XX_RESP_ID_REQD');
         fnd_msg_pub.ADD;
      END IF;

      RAISE fnd_api.g_exc_error;
   END IF;

   OPEN l_resp_csr;

   FETCH l_resp_csr
    INTO l_dummy;

   IF l_resp_csr%NOTFOUND
   THEN
      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_error)
      THEN
         -- Define the Custom message as XX_RESP_ID_INVALID with
         -- Description as "The specified responsibility is invalid."
         fnd_message.set_name('XX_APPL_NAME', 'XX_RESP_ID_INVALID');
         fnd_msg_pub.ADD;
      END IF;

      CLOSE l_resp_csr;

      RAISE fnd_api.g_exc_error;
   ELSE
      CLOSE l_resp_csr;
   END IF;

   IF    p_user_id IS NULL
      OR p_user_id = fnd_api.g_miss_num
   THEN
      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_error)
      THEN
         -- Define the Custom message as XX_USER_ID_REQD with
         -- Description as "A valid user ID is required."
         fnd_message.set_name('XX_APPL_NAME', 'XX_USER_ID_REQD');
         fnd_msg_pub.ADD;
      END IF;

      RAISE fnd_api.g_exc_error;
   END IF;

   OPEN l_user_csr;

   FETCH l_user_csr
    INTO l_dummy;

   IF l_user_csr%NOTFOUND
   THEN
      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_error)
      THEN
         -- Define the Custom message as XX_USER_ID_REQD with
         -- Description as "The specified user ID is invalid."
         fnd_message.set_name('XX_APPL_NAME', 'XX_USER_ID_INVALID');
         fnd_msg_pub.ADD;
      END IF;

      CLOSE l_user_csr;

      RAISE fnd_api.g_exc_error;
   ELSE
      CLOSE l_user_csr;
   END IF;

   fnd_global.apps_initialize(user_id  => p_user_id
                            , resp_id  => p_responsibility_id
                            , resp_appl_id => p_resp_appl_id
                             );
EXCEPTION
   WHEN fnd_api.g_exc_error
   THEN
      p_return_status                       := fnd_api.g_ret_sts_error;
      fnd_msg_pub.count_and_get(p_count     => p_msg_count, 
                                p_data      => p_msg_data);
   WHEN fnd_api.g_exc_unexpected_error
   THEN
      p_return_status                := fnd_api.g_ret_sts_unexp_error;
      fnd_msg_pub.count_and_get(p_count => p_msg_count, 
                                p_data  => p_msg_data);
   WHEN OTHERS
   THEN
      p_return_status    := fnd_api.g_ret_sts_unexp_error;

      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
      THEN
         fnd_msg_pub.add_exc_msg(p_pkg_name       => g_pkg_name,                                          p_procedure_name => l_api_name);
      END IF;

      fnd_msg_pub.count_and_get(p_count => p_msg_count, 
                                p_data  => p_msg_data);
END set_global_info;

Wednesday, March 19, 2014

Useful Scripts for Unix

CAT

The cat command reads one or more files and prints them to standard output. The operator > can be used to combine multiple files into one. The operator>> can be used to append to an existing file.

SYNTAX
The syntax for the cat command is:
cat [options] [files]

OPTIONS
Option
Description
-e
$ is printed at the end of each line. This option must be used with -v.
-s
Suppress messages pertaining to files that do not exist.
-t
Each tab will display as ^I and each form feed will display as ^L. This option must be used with -v.
-u
Output is printed as unbuffered.
-v
Display control characters and nonprinting characters

EXAMPLE
cat file1
cat file1 file2 > all
cat file1 >> file2

MAIL

The mail command allows you to read or send mail. If users is left blank, it allows you to read mail. If usershas a value, then it allows you send mail to those users.

SYNTAX
The syntax for the mail command is:
mail [options] [users]

OPTIONS FOR READING MAIL


Option
Description
-e
Check if mail exists. Exit status is 0 if mail exists and 1 if mail does not exist.
-f file
Read mail from mailbox called file.
-F names
Forward mail to names.
-h
Displays messages in a window.
-i
Ignore interrupts
-p
Displays all messages.
-P
Displays all messages with header lines.
-q
Terminate when an interrupt occurs.
-r
Displays oldest messages first.
-U
Convert uucp-type addresses to Internet format.
-v
Verbose.
OPTIONS FOR SENDING MAIL
Option
Description
-m type
Display a "Message-type:" line at the heading of the message, followed by type.
-t
Display a "To:" line at the heading of the message with the names of the recipients.
-w
Send mail to users without waiting for a remote transfer program to finish.
-F
Save message in a file called the name of the first recipient.
-h n
If message has not been sent after n network connections, do not send message.
-i
Ignore interrupts
-r address
address is the return address for mail messages.
-s subject
Displays subject in the subject header.
-U
Convert uucp-type addresses to Internet format.
-v
Verbose.


MAN

The man command displays the online manual pages.

SYNTAX
The syntax for the man command is:
man [options] [ [section] subjects]

OPTIONS
Option
Description
-
Output is piped through the more command.
-d
Debug.
-F
Search the MANPATH directories.
-f files
Display a summary (one line) for each file.
-k keywords
Displays the header lines that contain any of the keywords.
-M path
Searchs in the path instead of the MANPATH directories.
-t
Format the pages with troff.
-T mac
Display using mac.

EXAMPLE
man -f tech


TAIL
The tail command displays the last ten lines of the file.

SYNTAX
The syntax for the tail command is:
tail [options] [file]

OPTIONS

Option
Description
-f
Follow the file as it grows.
-r
Displays the lines in the reverse order.
-n[k]
Displays the file at the nth item from the end of the file.
+n[k]
Displays the file at the nth item from the beginning of the file.

EXAMPLE
tail -r tech

FTP

The ftp command allows you to transfer files to and from a remote server.

SYNTAX
The syntax for the ftp command is:
ftp [options] [hostname]

OPTIONS

Option
Description
-d
Debugging is enabled.
-g
Filename globbing is disabled.
-i
Interactive prompting is disabled.
-n
When you are initially connecting, auto-login is disabled.
-v
Display all responses from the server.

EXAMPLE
ftp tech
ftp -v tech

MORE

The more command displays the file called namein the screen. The RETURN key displays the next line of the file. The spacebar displays the next screen of the file.

SYNTAX
The syntax for the more command is:
more [options] [files]

OPTIONS

Option
Description
-c
Page through the file by clearing the window. (not scrolling).
-d
Displays "Press space to continue, 'q' to quit"
-f
Count logical lines rather than screen lines (wrapping text)
-l
Ignores form feed (^L) characters.
-r
Display all control characters.
-s
Displays multiple blank lines as one blank line.
-u
Does not display underline characters and backspace (^H).
-w
Waits for a user to press a key before exiting.
-n
Displays n lines per window.
+num
Displays the file starting at line number num.
+/pattern
Displays the file starting at two lines before the pattern.

EXAMPLE
more -d tech


GREP

The grep command allows you to search one file or multiple files for lines that contain a pattern. Exit status is 0 if matches were found, 1 if no matches were found, and 2 if errors occurred.

SYNTAX
The syntax for the grep command is:
grep [options] pattern [files]

OPTIONS

Option
Description
-b
Display the block number at the beginning of each line.
-c
Display the number of matched lines.
-h
Display the matched lines, but do not display the filenames.
-i
Ignore case sensitivity.
-l
Display the filenames, but do not display the matched lines.
-n
Display the matched lines and their line numbers.
-s
Silent mode.
-v
Display all lines that do NOT match.
-w
Match whole word.

EXAMPLE
grep -c tech file1
PS
The ps command displays active processes.

SYNTAX
The syntax for the ps command is:
ps [options]

OPTIONS

Option
Description
-a
Displays all processes on a terminal, with the exception of group leaders.
-c
Displays scheduler data.
-d
Displays all processes with the exception of session leaders.
-e
Displays all processes.
-f
Displays a full listing.
-glist
Displays data for the list of group leader IDs.
-j
Displays the process group ID and session ID.
-l
Displays a long listing
-plist
Displays data for the list of process IDs.
-slist
Displays data for the list of session leader IDs.
-tlist
Displays data for the list of terminals.
-ulist
Displays data for the list of usernames.


EXAMPLE
ps -ef
ps -aux



Hopefully this has helped some of you out and I’d appreciate any comments you have.

API Script to add the responsibilities to a user

DECLARE
   CURSOR c_resp
   IS
      SELECT fav.application_short_name
           , fav.application_name
           , frv.responsibility_key
           , frv.responsibility_name
        FROM fnd_application_vl fav
           , fnd_responsibility_vl frv
       WHERE frv.application_id = fav.application_id
         AND frv.responsibility_name IN ( 'Application Developer');

 l_user_name             VARCHAR2 (15) := '&USER_NAME';
 l_appl_short_name       fnd_application_vl.application_short_name%TYPE;
 l_resp_name             fnd_responsibility_vl.responsibility_name%TYPE;
 l_resp_key              fnd_responsibility_vl.responsibility_key%TYPE;
 l_description           VARCHAR2 (100) := 'Adding Responsibility to the user using script';
BEGIN
   FOR resp_rec IN c_resp
   LOOP
      l_appl_short_name    := resp_rec.application_short_name;
      l_resp_key           := resp_rec.responsibility_key;
      l_resp_name          := resp_rec.responsibility_name;

      BEGIN
         fnd_user_pkg.addresp (username          => l_user_name
                             , resp_app          => l_appl_short_name
                             , resp_key          => l_resp_key
                             , security_group    => 'STANDARD'
                             , description       => l_description
                             , start_date        => SYSDATE
                             , end_date          => NULL
                              );
         COMMIT;
         DBMS_OUTPUT.put_line ('The responsibility ' || l_resp_name || ' is added to the user ' || l_user_name);
      EXCEPTION
         WHEN OTHERS
         THEN
            DBMS_OUTPUT.put_line (   'Responsibility '
                                  || l_resp_name
                                  || ' IS NOT added to the user '
                                  || l_user_name
                                  || ' due to '
                                  || SQLCODE
                                  || '; '
                                  || SUBSTR (SQLERRM, 1, 250)
                                 );
            DBMS_OUTPUT.put_line ('');
            ROLLBACK;
      END;
   END LOOP;

END;

API script to Disable the enabled Responsibilities for a User

DECLARE
   --cursor to get all inactive users
   CURSOR cur_inactive_user
   IS
      SELECT fu.user_id
           , fd.responsibility_id
           , fd.responsibility_application_id
           , fd.security_group_id
           , fd.start_date
           , fd.end_date
        FROM fnd_user fu
           , fnd_user_resp_groups_direct fd
       WHERE fu.user_id = fd.user_id
         AND (   fu.end_date <= SYSDATE
              OR fu.end_date IS NOT NULL)
         AND fd.end_date IS NOT NULL
         AND fu.user_id = :p_user_id;
BEGIN
   FOR rec_inactive_user IN cur_inactive_user
   LOOP
--checking if the responsibility is assigned to the user
 IF (fnd_user_resp_groups_api.assignment_exists (rec_inactive_user.user_id, rec_inactive_user.responsibility_id, rec_inactive_user.responsibility_application_id, rec_inactive_user.security_group_id))
     THEN
         -- Call API to End date the responsibility
         fnd_user_resp_groups_api.update_assignment
        (user_id           => rec_inactive_user.user_id
       , responsibility_id => rec_inactive_user.responsibility_id
       , responsibility_application_id => rec_inactive_user.responsibility_application_id
       , security_group_id => rec_inactive_user.security_group_id
       , start_date        => rec_inactive_user.start_date
       , end_date          => NULL
       , description       => NULL);
         COMMIT;
      END IF;
   END LOOP;
END;