Skip to content
🤔prompts chat🧠
🔍
question:In servicenow, i have a table task_card. My requirement is if the time card is being inserted and Category Is Task_work then cost center field should be automatically updated to cost center value on the task record,(Cost Center is the reference field on both the tables).

answer:To achieve your requirement in ServiceNow, you can make use of Business Rules. A Business Rule is a server-side script that runs when a record is displayed, inserted, updated, deleted, or when a table is queried. It can be set to run before or after the database action has occurred. In your case, you would use a "before insert" business rule to update the Cost Center field on the `task_card` record based on the related Task record's Cost Center, given the `category` field is equal to "Task_work". Here's a step-by-step guide on how you can set up this Business Rule: 1. **Navigate to System Definition > Business Rules** in your ServiceNow instance. 2. Click on the **New** button to create a new Business Rule. 3. **Fill out the form** as follows: - **Name**: Give your Business Rule a name, e.g., `Update Cost Center from Task`. - **Table**: Select the `task_card` table from the dropdown. - Ensure the **Advanced** checkbox is checked to write a script. - **When to run**: Check the **before** checkbox since you want this to run before the insert operation is committed to the database. Also, check the **insert** checkbox since you want this to run on record insertion. - In the **Filter Conditions** area, you could add a condition to only run this rule when the `category` equals `Task_work` to ensure it only runs under the specific condition you mentioned. 4. **Script**: ``` (function executeRule(current, previous /*null when async*/) { // Check if the category is 'Task_work' if (current.category == 'Task_work') { // Reference the related task record var taskGR = new GlideRecord('task'); if (taskGR.get(current.task)) { // Assuming 'task' is the reference field to the task table // Set the Cost Center value from the related task record to the task_card record current.cost_center = taskGR.cost_center; } } })(current, previous); ``` 5. Save your Business Rule. This script checks if the `category` is `Task_work` for the `task_card` being inserted. Then, it looks up the related Task record using the `GlideRecord` API and fetches the `cost_center` from that record. If found, it updates the `task_card`'s `cost_center` field to match before the record is inserted into the database. PLEASE NOTE: - Replace `'task'` with the actual name of the reference field in the `task_card` table that points to the related Task record, if it's named differently in your setup. - Ensure you have the necessary access rights to create a Business Rule and modify the `task_card` table. - Test this solution in a sub-production or test instance before deploying it in your production environment to avoid any unintended side effects. - Business Rules can significantly impact system performance. Ensure your conditions and scripts are optimized for efficiency.

question:In servicenow, i have a table task_card. My requirement is if the time card is being inserted and Category Is Task_work and cost center field is empty then cost center field should be automatically updated to cost center value on the task record,(Cost Center is the reference field on both the tables).

answer:To address the updated requirement where the Cost Center field should only be automatically filled from the Task record if it is initially empty, you can modify the Business Rule by adding a condition to check if the `cost_center` field on the `task_card` is empty before fetching and setting the value from the related Task record. You can follow the same steps as outlined previously for creating a Business Rule, with a slight adjustment to the script: # Steps: 1. **Navigate to System Definition > Business Rules** in your ServiceNow instance. 2. Click on the **New** button to create a new Business Rule. 3. **Fill out the form** as per the instructions given previously, with an emphasis on: - **Name**: A descriptive name, such as `Update Cost Center from Task if Empty`. - **Table**: Choose the `task_card` table. - **Advanced**: Ensure this checkbox is checked. - **When to run**: Opt for **Before** and **Insert** to ensure the rule runs before a new `task_card` is inserted. You may also want to apply this rule on **Update** if you wish for the Cost Center to be filled in the event it's emptied in an update operation and the rule's conditions are still met. - **Filter Conditions**: Though you can specify the category as `Task_work` here, for more complex logic, you might prefer handling that within the script. This way, you can have more control over checking if the `cost_center` field is empty. 4. In the **Script** field, modify the provided code snippet to include a check on the `cost_center` field: ```javascript (function executeRule(current, previous /*null when async*/) { // Check if the category is 'Task_work' and the cost_center is empty if (current.category == 'Task_work' && current.cost_center.nil()) { // Reference the related task record var taskGR = new GlideRecord('task'); if (taskGR.get(current.task)) { // Assuming 'task' is the reference field name to the task table // Check if the task record has a cost_center defined if (!taskGR.cost_center.nil()) { // Set the Cost Center value from the related task record to the task_card record current.cost_center = taskGR.cost_center; } } } })(current, previous); ``` 5. **Save** your Business Rule. This script now only updates the `cost_center` on the `task_card` if it's initially empty (`current.cost_center.nil()`), ensuring it doesn't overwrite any existing values in the `cost_center` field unless those conditions are met. # Additional Considerations: - **Testing**: Confirm the functionality in a sub-production instance before deploying it to production. - **Performance**: Ensure that the rule is optimized to not adversely affect system performance. - **Accessibility**: Verify that you have the necessary permissions to create and modify Business Rules and the target table (`task_card`). By following these revised steps, you should be able to meet your requirement of conditionally filling the `cost_center` field on the `task_card` table based on the associated Task record, but only if it is empty at the time of insertion.

question:There is one table called Assessment instance in that table when state is completed. at that time there is one custom table called F&F in that table there is one field called interviews conducted in witch 2 choices are available Yes/No it should automatically set as yes. in short when Assessment instance's state is completed at that time FNF tables field ( Interview conducted) should set as yes.

answer:To achieve this functionality in ServiceNow, you can create a Business Rule on the "Assessment Instance" table that triggers when the state changes to "Completed". This Business Rule will then update the associated record(s) in your custom "F&F" table to set the "Interviews Conducted" field to "Yes". Here’s how you can set it up step-by-step: # Step 1: Identify the relationship between "Assessment Instance" and "F&F" Table Before writing the Business Rule, you need to understand the relationship between the "Assessment Instance" table and your custom "F&F" table. Specifically, you need to identify how these tables are linked (e.g., through a reference field, a related list, etc.). # Step 2: Create a Business Rule 1. **Navigate to System Definition > Business Rules** in your ServiceNow instance. 2. Click on the **New** button to create a new Business Rule. 3. **Fill out the form**: - **Name**: Enter a descriptive name like `Set Interview Conducted on F&F Completion`. - **Table**: Select the "Assessment Instance" table from the dropdown list. - **When to run**: - Check the `After` checkbox, as you want this to run after the record has been updated. - Choose `Update` to have the script run when an assessment instance is updated. - Under **Conditions**, specify the script to run only when the record's `state` changes to "Completed". You can use the condition builder or script if it’s a complex condition. 4. **Advanced**: - Check the **Advanced** checkbox to write a script for your Business Rule. 5. **Script**: ```javascript (function executeRule(current, previous /*null when async*/) { // Ensure the script runs only if the state is set to 'Completed' if (current.state == 'completed' /* Use the appropriate value or field that represents "Completed" status */) { // Fetch the related F&F record. Assuming 'assessment_instance' is the reference field in F&F pointing back to Assessment Instance var ffGR = new GlideRecord('custom_ff_table'); // Replace 'custom_ff_table' with the actual table name of F&F ffGR.addQuery('assessment_instance', current.sys_id); // Adjust 'assessment_instance' to the correct field name if needed ffGR.query(); while (ffGR.next()) { // Assuming 'interviews_conducted' is the field you want to set to 'Yes' ffGR.interviews_conducted = 'yes'; // Adjust 'yes' if the choice value for "Yes" is different in your setup ffGR.update(); } } })(current, previous); ``` 6. **Save** the Business Rule. # Points to Note: - Replace `'completed'`, `'custom_ff_table'`, `'assessment_instance'`, and `'interviews_conducted'` with the actual values from your instance. The choice value for "Yes" in the `interviews_conducted` field should correspond to the internal value stored in your choice list. - This script assumes a one-to-many relationship from "Assessment Instance" to "F&F", where multiple "F&F" records could relate back to a single "Assessment Instance". - Test this functionality thoroughly in a sub-production instance before moving it to production to ensure no unintended behaviors. By following these steps, you are linking the completion of an Assessment Instance to the automatic updating of related records in your "F&F" table, streamlining what could otherwise be a manual process.

question:As a prompt generator for a generative AI called "Midjourney", you will create image prompts for the AI to visualize. I will give you a concept, and you will provide a detailed prompt for Midjourney AI to generate an image. Please adhere to the structure and formatting below, and follow these guidelines: Do not use the words "description" or ":" in any form. Do not place a comma between [ar] and [v]. Write each prompt in one line without using return. Structure: [1] = 电梯厅设计,线条流畅,曲线形状 [2] = a detailed description of [1] with specific imagery details. [3] = a detailed description of the scene's environment. [4] = a detailed description of the compositions. [5] = a detailed description of the scene's mood, feelings, and atmosphere. [6] = A style (e.g. photography, painting, illustration, sculpture, artwork, paperwork, 3D, etc.) for [1]. [7] = a detailed description of the scene's mood, feelings, and atmosphere. [ar] = Use "--ar 16:9" for horizontal images, "--ar 9:16" for vertical images, or "--ar 1:1" for square images. [v] = Use "--niji" for Japanese art style, or "--v 5" for other styles. Formatting: Follow this prompt structure: "/imagine prompt: [1], [2], [3], [4], [5], [6], [7], [ar] [v]". Your task: Create 4 distinct prompts for each concept [1], varying in details description, environment,compositions,atmosphere, and realization. Write your prompts in english. Do not describe unreal concepts as "real" or "photographic". Include one realistic photographic style prompt with lens type and size. Separate different prompts with two new lines. Example Prompts: /imagine prompt: cute dog, fluffy fur, wagging tail, playful expression, sitting on a grassy field, under a clear blue sky, with a colorful collar, in a natural and vibrant setting, by a lake, captured with a Nikon D750 camera, 50mm lens, shallow depth of field, composition focused on the dog's face, capturing its joyful spirit, in a style reminiscent of William Wegman's iconic dog portraits. --ar 1:1 --v 5.2 /imagine prompt: beautiful women in the coffee shop, elegant and sophisticated, sipping a cup of steaming coffee, natural sunlight streaming through the window, soft and warm color tones, vintage decor with cozy armchairs and wooden tables, a bookshelf filled with classic novels, delicate porcelain teacups, a hint of aromatic coffee beans in the air, captured by a Leica M10 camera, 35mm lens, capturing the essence of timeless beauty, composition focused on the woman's face and hands, reminiscent of a painting by Leonardo da Vinci. --ar 1:1 --v 5.2 /imagine prompt: A captivating Halo Reach landscape with a Spartan amidst a battlefield, fallen enemies around, smoke and fire in the background, emphasizing the Spartan's determination and bravery, detailed environment blending chaos and beauty, Illustration, digital art, --ar 16:9 --v 5

answer:/imagine prompt: modern elevator hall design, sleek and minimalist lines, curved glass panels, futuristic lighting fixtures, polished marble floors, overlooking a bustling cityscape, with panoramic windows, a high-tech elevator door in the center, reflecting the urban skyline, capturing the essence of urban sophistication and luxury, in a photography style with a wide-angle lens, emphasizing the architectural details and the expansive view. --ar 16:9 --v 5.2 /imagine prompt: elegant elevator lobby, Art Deco inspired design, ornate golden trimmings, crystal chandeliers, velvet seating, intricate mosaic flooring, surrounded by grand marble pillars, arched doorways leading to different floors, a vintage elevator with brass accents, set in a historical building, exuding a sense of timeless elegance and opulence, in a painting style reminiscent of classic architectural illustrations. --ar 9:16 --v 5 /imagine prompt: industrial elevator hall, raw and rugged design, exposed metal beams, concrete floors, hanging pendant lights, graffiti art on the walls, metal staircases leading up, scattered tools and equipment, a sense of organized chaos, with a gritty urban vibe, capturing the essence of urban grit and creativity, in a 3D artwork style with high contrast lighting and textures. --ar 16:9 --v 5 /imagine prompt: futuristic elevator vestibule, high-tech and sci-fi inspired design, interactive holographic displays, neon lighting accents, digital artwork panels, floating platforms, robotic assistants, a sense of advanced technology and innovation, set in a space station or futuristic city, with a dynamic and futuristic atmosphere, in an illustration style with a cyberpunk aesthetic, showcasing the merging of technology and architecture. --ar 16:9 --v 5.

Released under the stanford License.

has loaded